This is my submission for Mollys Chemicals. Can someone tell me why it times out ? I calculated the Time complexity as follows — please correct me if I am wrong. 1. The preProcess function would work in O(46 log(46)). 2. The prefix sum computation takes O(n); 3. The subarray generation part (in the while loop) takes O(n^2 * log(46)) . (Because the set size would atmost be 46).
So adding them, O(46 log(46)) + O(n) + O(n^2 * log(46)) and with the constraint over n as 10^5, 46*5 + 10^5 + (10^10)*5.
Assuming 10^9 operations per second, the time limit given for the problem is 2.5 secs which means 10^27 operations can be allowed. Then why does my solution give TLE?
Please help me.