The Leetcode Missing Guide

Regardless of your experience and skill level, you can effectively learn from Leetcode if you know how to use it the right way. Learn the reasoning behind a solution and how they derived that solution. After a few days, go back and solve the same problem again from scratch without any reference. Even if you remember the gist of the solution, you would still have to implement it again, which can be a challenge. You can also look at the solution in a different language and code it in a language more familiar to you. Understand the thought process behind a solution and how to derive it. Ideally use only the hints so you don’t look at the complete solution and have the chance to solve the problems on your own. But the goal is to reach a state where you can come up with optimal solutions without looking at the answer. This just takes practice and time.

Build a solution from scratch. Get into the habit of getting your implementation to work. If you have difficulty to get it to work, you can then rule it out and move on to another approach. Speed should not be the focus. Developing a method of working through the problem in a methodical way with a set number of steps is the goal. Speed will be a byproduct of refining your method of approaching a problem you’ve never seen before.

Part of the process is working through frustration, finding a starting point and building confidence in your solution. You must expect to work through those uncomfortable moments. Do not look at the solution until you have your own working implementation. Do not write a single line of code until you have written what you think is an entire working solution on paper.

If you are passing some of the test cases and can’t think of any other solution after spending a significant amount of time on it then look up the solution. Read the algorithm and then implement it. Do not look at the solution and copy and paste the solution in to add a +1 to your record.

There’s no shortcuts. It’s hard work, discipline and spending time working through it. The point isn’t solving the problem. The point is improving your problem solving skills and communicating how you’re going to approach the problem before writing code.

The hard part isn’t solving the problems themselves, but rather overcoming the mental barriers and having the discipline to solve the problems consistently.

Fundamentals

It is important to build a foundation, essentially a set of basic building blocks that can be used to dissect each new problem into solvable sub problems. Learn the computer science basics. Read and work through the explore section.

Milestone 1 : Practice Readiness Checklist

Crawl Phase

Work through easy problems and learn to improve brute force solutions.

  • Sort the problems by descending acceptance rate.
  • Solve the problems without using any hints. Atleast get the brute force solution working.
  • Come up with all the test cases and aim to get accepted on the first submission.
  • Study how the top solutions apply the tricks to improve the performance.
  • Read the comments and ask questions.

Milestone 2 : Implement Optimal Solution for Medium Problems within 30 Minutes

Walk Phase

Work through medium problems and learn to classify the problem.

  • Read the problem statement and look for clues.
  • Implement the solution even if it is not optimal.
  • Look at the top solutions and learn what you improve and alternative methods to solve the problem.
  • Understand the thought process and implement the optimal solution based on your understanding without looking at any hints.

Run Phase

Work through hard problems and learn to identify the right approach to solve the problem. The hard problems usually take more than 45 minutes to come up with a working solution.

  • Simplify the problem by removing time or space constraints and come up with a brute force solution.
  • Identify what parts of your solution can be optimized to satisfy constraints.
  • Read the top solutions and understand the thought process.
  • Learn about the right data structure and algorithms to use and how to handle the corner cases.
  • Develop you pattern recognition skill. Categorize types of approaches to problems based on features you have seen before.

Milestone 3 : Implement Optimal Solution for Hard Problems within 45 Minutes

Enjoy the Journey

I wanted the reward and not the struggle. I wanted the result and not the process. I was in love not with the fight but only the victory. And life doesn’t work that way.
Mark Manson

Comments (5)