please give the corrected code as i think this is the best solution available
Can you please tell why my code is giving TLE
your solution approach is correct, actually the test case have n=10000, , so a little bit of optimization will work!
see this