Can any body plz tell me why the second soln gives TLE. Thns in advance.
Logically the solution seems correct, but If you check other solutions using loops, then it seems that your code runs the loop more number of times for each test case, which cumulatively results in a TLE. For e.g run the testcase “#…###.#…###” using your code and using http://www.codechef.com/viewsolution/2289297 . You would see that the number of times loop runs is more in your case.