← All posts
3 min read

LeetCode Easy Notebook - the plan

#leetcode#algorithms#interview-prep
📑 On this page

The goal is not to dump answers. The goal is to build a notebook I can come back to before interviews and immediately remember the shape of the thinking.

For every Easy problem, I want the post to answer five things:

  1. What is the problem really asking?
  2. What is the first naive idea?
  3. What pattern does the problem belong to?
  4. What optimization makes it clean?
  5. What are the trade-offs and edge cases?

That means the LeetCode Notebook will stay as one series, and each solved Easy problem will be another entry inside it.

The writing template

Every solution should follow roughly this structure:

The problem in plain English

Before code, rewrite the problem. If I cannot explain it simply, I have not understood it yet.

The naive instinct

Start with the obvious solution, even when it is too slow. This is not wasted space. The naive version shows what the optimized version improves.

The reframe

This is the most important section. The reframe should name the pattern:

Problem smellPattern to try
"Have I seen this before?"Hash map / set
"Nearest previous/next thing"Stack
"Sorted array"Two pointers / binary search
"Subarray/window"Sliding window
"Count ways"Dynamic programming
"Tree path or depth"DFS / BFS
"Linked list pointer movement"Fast and slow pointers

The accepted solution

Keep the code small and interview-readable. Prefer Python first because it makes the idea visible.

Other possibilities

This is where the notebook becomes useful:

  • Could sorting help?
  • Could a set replace a map?
  • Could recursion be made iterative?
  • Could this be solved in one pass?
  • What changes if the input is huge?
  • What changes if there are duplicates?

Complexity

End with time and space complexity, plus the reason behind each one.

First Easy batches

I will work through Easy problems by pattern, not random order.

BatchFocusExamples
1Hash maps and setsTwo Sum, Contains Duplicate, Valid Anagram
2StacksValid Parentheses, Baseball Game, Backspace String Compare
3Two pointersPalindrome checks, Merge Sorted Array, Remove Duplicates
4Sliding windowBest Time to Buy and Sell Stock, Maximum Average Subarray
5Binary searchSearch Insert Position, Sqrt(x), First Bad Version
6Linked listsReverse Linked List, Merge Two Sorted Lists, Linked List Cycle
7TreesMaximum Depth, Same Tree, Invert Binary Tree
8Dynamic programmingClimbing Stairs, Min Cost Climbing Stairs

The notebook can grow problem by problem, but the hidden curriculum is pattern recognition. That is the part that compounds.