Time Limit Exceed error solution in C++

In this tutorial of CodeSpeedy, we will learn about the Solution of Time Limit Exceed error. If you don’t know anything about the Solution of Time Limit Exceed error and the different ways to overcome this problem. It’s OK, you are in the right place, let’s go through it.

What is the Time limit exceed? Time Limit Exceeded also known as TLE. TLE simply means that your program is failed or unable to finish its execution before the given time limit for that problem.

The reason behind Time limit exceed:-
  • Restrictions on time:-  To understand TLE in a better way, firstly understand the online judging. For the evaluation of every program submission, various resources like memory, time, and CPU are allocated by the judges. So that each programmer can use the same resource and hence helps in fair conduction of competition. However, to make sure that your solution for the program does finish its execution within the time decided by the problem setter. Your submission is allowed to run only for the given time. And after that period online judge stops your program execution. And this will result in TLE.
  • Slow reading input/writing output method:-  Sometimes, the programmer uses methods that are comparatively slow concerning other methods for taking input for execution and displaying output may also result in TLE. Always try to choose appropriate input-output functions. For example, In Java try to use a BufferedReader instead of a scanner method.
  • Reduce the Bounds of the loop:- Use the bound in the input of loops very carefully. It will also result in TLE if you use large no. such as  N <= 100000 or N<=10000000, and your program contains nested loops.
  • Optimize your Algorithm:-  If everything works well, then you should change the algorithm to solve your problem. Try using a different algorithm to overcome the problem of TLE.
  • Server Configuration:- Lastly, Server Configuration will also result in TLE sometimes. The time taken by the code to complete its execution (online competition ) will also depend on the speed and the architecture of the server.


These are some important reasons behind TLE.

Check out the solution for more problem on codespeedy-

Leave a Reply