What to do when i am stuck and don,t understand what to do?

i am new to CP , i code something in my IDE and it work fine on it but as soon as i put it on thus online IDE there is always an error . time limit exited(TLE ) a really frequent one.
What should i do to optimize my code ?

Welcome to CP!
Well, first of all understand that the online judge accepts solutions if your code gives the correct output for the hidden test cases too, not only the sample ones that you see on the problem statement page. Try giving more time to debug your code (yeah, that can be really frustrating at times :stuck_out_tongue_winking_eye:), find the corner cases, learn about various types of approaches and algorithms, and optimise your code according to the given constraints, and simplify time complexity.

Coming to your special mention about TLE, it’s all because your program is too slow for the given inputs. That can just be solved by changing your approach and optimising (depnds on specific question and its constraints) the code.

You might want to go through the following to understand TLE:

You can always read editorials, they’ll really help you build your step-by-step approach. Participate in contests and practice problems according to the difficulty level that suits you. Also, the forum is always open for your genuine doubts and problems. We all are happy and willing to help you out in case you get stuck anywhere.
Happy coding! :smiley:

4 Likes

Thank you so much @manvi_03 for your reply.
After reading all the suggestions now I have better idea of how things work and on what i have to work on more.

1 Like

For TLE try to think in a way how you can reduce your code time complexity like can you reduce any query which you can do in constant runtime but you are using a loop for e.g something uniquely associated linked component you can use map and access it in constant time but you are using vector and everytime you want to access it you use find function which is performing linear time searching (if not sorted ) so try to think it in that way and last but not least try to solve more and more problem if you stuck take a look at tutorial/editorial and eventually you will be good at it happy coding :smiley:

2 Likes

Thank you @sarvdeep_mark .

Glad to help :smiley:

1 Like