TLE in Problem WTCH

Hi,the program with the code WTCH is showing a TLE with alinear algorithm and I don’t know how it can be made more effecient.
Following is the link to my solution:
https://www.codechef.com/viewsolution/28615811

Your code is O(n^2) as substring() is O(n) as stated here.

1 Like