O(n) approach giving TLE in Rich substrings

I used prefix sum array to solve RICHSTR problem of august cookoff which is o(n) solution. But it is giving TLE!!!
Can someone help me in this
Link to my solution:
https://www.codechef.com/viewsolution/26050602

Use fast I/O. Same happened with me during contest (+10 min penalty).

1 Like

Thank you. Its working now

1 Like