time limit

hello friends , i m new on online coding and don’t know much about time limit of a program…i submitted a solution and its written that time limit exceeded now what to do ?

time limit exceeded means your algorithm is taking more time than the excepted time(i.e time limit will be given at the bottom of the page). so try to optimize your code or better to change your logic for the problem. Don’t try to solve the problem in O(n^2) complexity it will definitely lead to TLE(time limit exceeded) in most of the cases. If you don’t know how to optimize more, post the link of your problem and your solution, but try to optimize on your own. try as many times as you can in different ways. it will improve your logical skills.

5 Likes

wanna ask one more question, what is the use of constraints do we have to implement in the algorithm ?

@prince9971 Constraints are been set up to tell you the data types/ amount of memory that you have to use.
Like for example if you are given a constraint on a variable say N that 1<=N<=10^9 then you have to use unsigned long long to declare N.
Unsigned because it is positive, long long because it exceeds the range of integers and that of long.
Hope this helps!

1 Like

Hi in FORGETPW Question of June Challenge, my execution time is 1.76 sec. But time limit is 1sec. Still the code get accepted. Could you tell me the reason?

1 sec time limit is just for one standard test file to be passed and after that 1.76 sec is the combined time for all the test files.

1 Like

What do you mean, “dont try to solve problem using O(n^2)” ? How can you conclude that O(n^2) solutions will give TLE without reading the problem and constraints. There are problems on codechef for which O(2^n) solutions pass!

@v_akshay i think you should read my comment once again, because i said in most of the cases it will lead to TLE. not every time

do constraints affect the execution time of a program ?

Yes, definitely.
Like the example I gave above if I declare N as unsigned int then it is capable of holding at the maximum 65,535. But since chef has put that the value may rise up to 10^9, whenever chef inputs an integer greater than 65,535, it would probably give you a RTE (precisely SIGSEGV) or WA. So, in order to avoid such errors your code should be exactly what the question demands.

As explained above time limit is defined for single file input not for the complete execution.