Are you looking for a tech job? Are you dreading your next technical interview? It's time to practice Leetcode problems. Here are seven ways to make sure you study smart, and get the most out of your time.
Write Stuff Down
Leetcode problems are hard. It's normal to struggle with them. But they're a lot harder than they need to be if you insist on doing everything in your head. Pen and paper are a powerful tool for thinking through a problem. You can write down a few simple examples and work through them manually. You can draw graphs and trees to help you visualize the problem. You can jot your thoughts down in bullet point form. It takes a little extra effort to unglue yourself from your computer and fetch pen and paper, but I promise, it'll be worth it.
Plan Ahead
Don't jump straight into writing code if you don't understand the problem yet. You wouldn't start driving before you know where you're going! First, make a plan. What algorithm are you using to solve the problem? Are there alternatives? What are the tradeoffs? What data structures will you need? How efficient will that be? Is there a way to speed it up? Is there a way to use less memory? Once you have a good high level plan sketched out for what your solution is going to look like, then it's time to start writing code.
Speak Up
Why are you practicing Leetcode problems? You want to be able to pass technical interviews! Then you should know that in an interview, you're not just being assessed on whether you arrived at a correct solution or not. Your interviewer wants to be able to communicate with you, they want to understand your thought process. Explaining your thought process is a very different skill than just solving the problem, so make sure you practice it! Talk to a friend or partner while solving a problem, or if no one is around just talk to yourself. When the time comes to show off your skills, you'll be glad you're prepared.
Set a Time Limit
If you've been practicing Leetcode problems, you know what it's like to get stuck. It's not a good feeling. Some people get discouraged and quit, some people get stubborn and spend hours on the same problem. It's easy to relate to both responses. Luckily, there's a better way. Give yourself a time limit per problem of 30 or 60 minutes. If you've tried your best, but at the end of the time limit, you don't know how to get it working, it's time to move on. I know it's frustrating, but if you're stuck, you're not making progress. So what should you do if you didn't figure out a solution on your own?
Look at the Solutions
Luckily you're not the only one practicing these problems! Leetcode publishes solutions for a lot of their problems, and if an official Leetcode solution isn't available, the discussion associated with the problem will always contain many different approaches. If you haven't solved your problem within the time limit allotted, just look at the solution. I know it feels like cheating, but it's not. I know it hurts your pride, but you'll survive. You need help, help is available, so use it. Also, solutions aren't just for problems you failed to solve. Even if you have a working solution, chances are it could be improved. Chances are someone else did it better. So look at what they did, learn from it, and use that to improve your own code.
Try, Try Again
Let's say you solved a problem, you like your solution, and you feel good about it. Time to forget about that problem forever, right? Nope! After two or three months have gone by, there's no guarantee you remember exactly what you did or how you did it. There's also a chance you've picked up some new problem solving tools along the way. If you breeze through it, great, not much time lost. If you get stuck again, great, you needed the practice. There's a good chance your solution will be a lot better the second time around, and comparing the two solutions can be a valuable learning experience. It's also good for your confidence to see how far you've come.
Find a Friend
Humans are social animals. We don't like doing things alone. Studying is no different. So find a friend to study with. You don't have to physically be in the same room, it doesn't even have to be a person you know in real life. There are lots of communities and discussion forums dedicated to whatever you're studying. When you find a cool problem, let them know about it. When they tell you they've found a cool problem, give it a try. The interaction makes studying a lot more fun and a lot less tedious. Together you'll get where you're going in no time!