what is the solution for time limit exceeded

My solution is showing time limit exceeded. What all can I do to solve this problem?

Check input constraints and reduce the time complexity of your approach appropriately.

Do make your code more optimised that will reduce the time complexity of your code to overcome TLE.

I can’t understand how to reduce the time complexity. Tried removing all the unnecessary output statements and replaced cin cout with scanf and printf respectively, still unable to submit successfully.

4 Likes