Time limit exceeded......? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Time limit exceeded......?

Well, I was participating in a coding competition on a website. When I tried to submit my code, I got an error that "time limit exceeded". I was using C++ in my programs, I even tried to change cin, cout to scanf, printf but nothing worked. The code is working perfectly on my device but not on website. Any help?

13th Jul 2019, 9:30 AM
Mohit Nagpal
Mohit Nagpal - avatar
4 Answers
+ 2
From what I know, coding competition usually put a time limit for the execution, like 1 second or 2 seconds. It looks like your code is taking a lot of time to be executed and doesn't satisfy the time limit. Your code works fine if there is no time limit
13th Jul 2019, 10:35 AM
Agent_I
Agent_I - avatar
+ 2
Mohit Nagpal Well usually competition like that relies heavily on using loop, so you can optimize it by making each iteration shorter and more effective, or you can use mathematical calculation to avoid using loops, if possible. There is nothing else in general I can give you, and I cannot give any specific solution since I don't know what the task is
13th Jul 2019, 11:21 AM
Agent_I
Agent_I - avatar
+ 1
Agent_I any idea on what can I do to improve my code?
13th Jul 2019, 11:13 AM
Mohit Nagpal
Mohit Nagpal - avatar
0
Agent_I ok. Thanks!
13th Jul 2019, 11:22 AM
Mohit Nagpal
Mohit Nagpal - avatar