# How An Online Judge Works And How To Avoid Time Limit Exceeded Problem?

• Last Updated : 10 Jun, 2020

In this article, you will get consent on how an online judge works and this article discusses very frustrating error Time Limit Exceed error that coders get at some point in time while solving the questions at online platforms. The article primarily discusses three things:

• How does an online judge work?
• Why do we get TLE?
• How to avoid TLE?

### Why Do We Get TLE?

When your algorithm doesnâ€™t have the required efficiency you get TLE so the idea is to complete the processing in a finite amount of time. Let’s assume you are calculating whether a number is prime or not and the number is of the order 10^18. If you are using the O(n) algorithm you are bound to get TLE and if you use the O(log N) algorithm you won’t get TLE. Below are some common reasons for TLE error…

• Online judges put some restrictions on time and it doesn’t allow you to process your instruction after that time limit. If you take more time than the time limit which is specified than you will get the TLE error.
• TLE error also depends on the server architecture, operating system, and the complexity of an algorithm. For different platform server architectures are different and the speed of the execution for the code varies on each server.
• If the programmer is using a slow method of reading and writing the input in the code then it will give you a TLE error.

### How To Avoid TLE?

1. Analyze the constraints: If the time limit is 1 sec, your processor is able to execute 10^8 operations.

2. Choose faster input and output method. For example:

• Use buffer reader in java, do not use Scanner
• In C++ use scanf/printf instead of cin/cout,
• Use these two statements in python for speeding up your execution

 `import` `psyco ` `psyco.full() `

3. Your program must not contain 4 nested loops if N<=100.

4. Sometimes too many nested loops can make your program slower. So it’s better to optimize your code and reduce the number of loops according to the instruction of input bound already specified in the question. So read the bounds in your code carefully and according to that write your program.

5. Optimize your algorithm or try to find a different solution for the problem statement using another data structure.

As the saying goes, the experience is the best teacher. The more you code the algorithms, the more efficient the geek you become in the coding.

Important Link: How to overcome Time Limit Exceed(TLE)?

My Personal Notes arrow_drop_up
Related Articles