(I’m a newbie programmer here and this is my first post, so please let me know if I commit any errors in the placement etc of this doubt.)
I have a doubt in Codeforces Round 173 Div 2B - the problem can be found here. My solution (which is getting Time limit exceeded is here. The official solution (seemingly so from the editorial) is here.
My doubts are:
- The official solution does not consider any case in which “-1” is the output, seemingly?
- My solution seems to be of complexity O(n), but it still gets TLE? Bound of n is 10^6 in the problem.
If someone can help me understand this, thanks a lot!