@abhishek_iiita I also tried to implement the solution using kmp algorithm, but without any extra lps array and period. Can you explain why the period is calculated for the substring?
I used the similar approach as yours for calculating the 2 lps arrays. While iterating over the original string I just checked the length of lps for two halves and if the they exceed the half lengths then I increment the count. Still getting a WA.
It was a good question and the story and all were interesting sir. It was my first time to get two acs in a cook-off . I felt bad in the morning when many said that my brute-force solution was not supposed to work ! The feeling that I didn’t deserve the increase in my rating made me feel bad . So I learnt hashing as suggested in tutorial and got ac for the question in practice. I don’t think that I would have learnt hashing if my brute-force failed. Something good did come out of this sir .
Thank you.
Just learned String hashing. So might be a weird question. In editorialist solution :
long getHash(int l, int r){return (MOD-(hash[r+1]*pow[r-l+1])%MOD+hash[l])%MOD;}
}
why we are taking range of substring(r+1,l) rather than (r,l-1) ? Please explain.
i have also used LPS(Prefix sum technique) as setter solution but i did not get it! why @rishup_nitdgp used the (len*2>(i+1)). could you please explain me the little bit!
@pastor Read about gcc compilers and try to find which gcc is your vs code running on. I mostly use ideone but seems like it still doesn’t support c++17. I used code and compile from codechef only.
For each iteration you are calculating the hashValue in O(n), thus making your overall complexity O(n*n) which will surely timeout. You need to do some preCalculation as you are calculating the same stuff again and again.
Have a look : CodeChef: Practical coding for everyone