When do you play with leetcode? Personally, I open it only before the algorithm interview.

It’s wrong actually, the algorithm is not only used in the interview but also really useful in the production, which also make you write the effective code in the daily work. Leetcode helps interview a lot indeed, I sometimes can see some guys who get the Google offer by leetcode, moreover, I believe more algorithm we learned, better engineer we can be.

This post is showing how I leetcode, it’s only my personal approach, I usually try to understand the one algorithm completely, then try to search by tag and resolve the problems from easy to hard.

The general steps to resovle a problem:

  1. Abstract the problem: Most questions are from some scenario in the real world, try to abstract the problem, transfer the problem to the computer world.
  2. Map to the data structure and algorithm: Do a brainstorm, map the problem to any data structur and algorithm that you are familiar with. If lucky it’s exactly matched, apply it.
    1. Don’t try to use smartest solution first, it’s probably time consuming, for example, maybe Brute Force at first then optimize it step by step.
    2. No any clue? congratulations! you get space to grow, don’t be too sad for the failure of one interview, the better future is waiting for you ahead.
  3. Implemente the solution: there’s a gap between the idea and the code, no magic here, practice more to improve the code skills.
  4. verify with some test cases and edge cases

Enjoy the Algorithm, let’s leetcode with the popular algorithm list:

Data Structure

Array

Linked List

Tree


The solutions for following three problems are similiar, which all base on the inorder traversal with stack

Discussion - Learn one iterative inorder traversal, apply it to multiple tree questions (Java Solution)


Heap

Binary

To master binary related problems, understanding the binary operation is the key point: ^, |, &, >> and <<

Stack

Algorithm

Recursion

Dynamic Programming

Quick Sort

Greedy

Math

Design