@alei the solution for BINARY talks of an amortized O(N) approach, but I implemented a similar algorithm with same complexity and still received TLE for 2 cases. Could you please explain that?
Here is my solution: CodeChef: Practical coding for everyone