To what degree should I optimze my code?

Hi everyone.

I am wondering to what degree should I optimize my code.

Sometimes although already developing my code whose complexity is same as editor’s one, I have spent much more time thinking better one. But usually my tries for looking for the better end up without success. :frowning:

When you solve problems, to what degree do you optimize your code? Do I have to repeat to enhance my code till I do not meet TLE?

Please share your experiences.

Thank you for reading my question.

It is completely based on algorithm that which you are using to solve the problem.

Most of the times the algorithm you are using should be efficient enough to give as minimum complexity as possible. Sometimes other things may also happen like your code generating infinite loops… you should also check that your code doesn’t generate infinite loop bcoz that will definitely lead to TLE… Hope this answers your question.