DEV Community

Cover image for Leetcode Practice Advice: Use ‘easy’ questions for exploration
Chad R. Stewart
Chad R. Stewart

Posted on

Leetcode Practice Advice: Use ‘easy’ questions for exploration

So practicing leetcode questions can be challenging. These questions tend to be constructed in a hyper-specific way where it is not very intuitive to come up with an answer, even for a seasoned engineer. Answering leetcode questions is a skill on it’s own that needs to be practiced to get any good at it. Getting good at this skill though can potentially be easier than people realize.

So first off, ‘easy’, ‘medium’ and ‘hard’ aren’t good descriptors of these questions as they can give a false sense of incompetency and, to be fair, potentially a false sense of competency too. Secondly, questions I’ve seen tend to follow this pattern:

  • Easy: “Multiple ways to solve the problem. Brute force solution is ok.”
  • Medium: “Solutions tend to be more involved versions of 'easy' questions. More optimal solutions tend to be encouraged through constraints.”
  • Hard: “Solutions tend to be a collection of 'medium' and 'easy' solutions put together based on what is being asked. Constraints usually make brute force solutions impractical.”

A key insight here is that as you go up the level of problem, the solutions to them tend to draw from solutions of the levels below with ‘easy’ questions having the most broad solution space.

So what I am proposing is this. Instead of doing ‘easy’ questions to check the box that you are competent at doing that level of problem, take the time to really explore the solution space of ‘easy’ problems. While brute force solutions are perfectly fine, you can also try to optimize your solution as best as you can. But even then, don’t limit yourself to simply trying to achieve the most optimal solution. Play around, try to come up with different ways of solving the problem. This can also be done with both 'medium' and 'hard' problems as well but I recommend ‘easy’ problems because their solutions tend to be the most accessible to people who try them which makes them perfect for this exercise.

What I’ve found is that there are times where optimizations require approaching the problem in a completely different way and/or doing so makes the problem easier or faster to solve. This practice also helps expand your toolkit that you can bring to bear to solve a problem. There are several times where I've had a 'hard' time solving a 'medium' problem and then after abandoning it and solving 'easy' problems, I’ve come up with a solution that can be used in the 'medium' problem I was stuck on. Also don’t be afraid to look up solutions and play around with those too. The goal of this exercise is to expand your toolkit and reading other people’s solutions and messing around with them does just that. Admittedly this is a very time intensive exercise so you’ll need to factor this into your schedule when practicing for interviews.

And that’s it really. So next time you’re doing a Leetcode question and you’ve come up with a solution, take the time to think about solving it another way and just play around with it. You might learn more playing around with a problem you’ve already solved than wrestling with a 'hard'er problem.

Top comments (0)