Best way to optimize solution for time limit

I have read many tutorials over the internet,please tell me an efficient way to optimize code against time limit exceeded.

Try FAQ. There you’ll find some of the best practices for your solutions to get accepted and don’t consume a lot of time. When solving a problem look at the constraints and see if your solution will waste a lot of time or not. You can also measure the time in your machine, try to test it with the worst case scenarios.

Most easy problems don’t require much thinking to come up with an acceptable solution, however, sometimes you’ll find problems that will need the use of some specific algorithm. The best way to know most of those algorithms is to practice (I’m saying this a lot this days). If you are willing to and have the time you can also buy books on algorithms and study them (Even when using a book you have to practice, it’s the only way to understand things).

In this site you will find a lot of problems to solve. Try the easy ones first. And you should check the editorials after solving them, most of the problems have one. You will learn a lot from them.

1 Like