LeetCode

This is my coding interview notebook: pattern reminders at the top, and one markdown page per completed problem underneath. The problem pages live in study/leetcodes/, so new captures from the Tampermonkey script can be added without deciding which topic file owns the question.

Use the pattern sections as a quick diagnosis checklist before solving. LeetCode tags can overlap heavily, so the important split here is the main thinking pattern, not every possible tag.

Pattern Notes

Arrays & Strings

Use this bucket for flat sequence problems where the core work is scanning, comparing, grouping, or maintaining a window.

Patterns to know

  • Two pointers: fast/slow, inward/outward, sorted pair search.
  • Sliding window for longest, shortest, or counted substring/subarray constraints.
  • Prefix sum and difference array for repeated range calculations.
  • Sorting plus greedy when order unlocks a simpler local choice.
  • Binary search on index or answer space.

How to identify

The input is mainly an array or string, and the question asks for a pair, triplet, range, substring, frequency, or ordered scan.

Dynamic Programming

Use this when the answer can be built from smaller repeated states and a local decision contributes to a global optimum or count.

Patterns to know

  • 1D DP for Fibonacci-style transitions, house robber, and simple recurrence states.
  • 2D grid DP for unique paths, minimum path sum, and obstacle grids.
  • Subsequence DP for LIS, LCS, edit distance, and matching problems.
  • Knapsack, interval DP, state machines, bitmask DP, and digit DP for richer state design.

How to identify

Look for maximum/minimum ways, cost, length, repeated subproblems, or a recursive brute force that keeps recomputing the same state.

Trees

Tree problems are usually about choosing the right traversal and deciding what each recursive call should return to its parent.

Patterns to know

  • DFS preorder, inorder, and postorder.
  • BFS level order with a queue.
  • Divide and conquer for height, balance, diameter, path sum, and subtree checks.
  • BST-specific inorder ordering and binary-search-like pruning.
  • Lowest common ancestor and ancestor/path tracking.

How to identify

The input is `root`, or the problem talks about height, depth, level, ancestor, subtree, balanced, path, or BST order.

Graphs

Graph questions are about relationships: reachability, connectivity, ordering, shortest path, or traversing a grid as implicit nodes.

Patterns to know

  • BFS and DFS for traversal, islands, and connected components.
  • Union-find for grouping and cycle detection.
  • Topological sort for prerequisites and dependency order.
  • Dijkstra or Bellman-Ford for weighted shortest paths.

How to identify

The input has nodes and edges, a 2D grid with movement, prerequisites, components, cycles, or a shortest path requirement.

Design Problems

Design problems ask you to maintain state across method calls while meeting operation complexity constraints.

Patterns to know

  • Hash map plus linked list for LRU-style ordering.
  • Hash map plus array for randomized set operations.
  • Queue/deque for recent-event windows, rate limiters, and hit counters.
  • Heap or ordered structures when min/max priority matters.

How to identify

The prompt asks you to implement a class with operations such as `push`, `pop`, `get`, `put`, `add`, or `remove`.

Backtracking

Backtracking is controlled brute force: build a candidate, recurse, then undo the choice cleanly.

Patterns to know

  • Subsets, combinations, and permutations.
  • Board search such as word search, N-Queens, and Sudoku.
  • Pruning invalid branches early.

How to identify

The problem asks for all possible solutions, all valid arrangements, or all combinations under constraints.

Heaps & Priority Queues

Use heaps when you repeatedly need the current smallest, largest, or best candidate without fully sorting every time.

Patterns to know

  • Kth largest or smallest.
  • Top-k frequent elements.
  • Merge k sorted streams.
  • Scheduling and running median style problems.

How to identify

The problem repeatedly asks for min/max, top-k, or the next best item while data changes.

Linked Lists

Linked list problems are pointer discipline problems. The main risk is losing references or mishandling edge cases.

Patterns to know

  • Fast/slow pointers for cycles and middle nodes.
  • Dummy nodes for cleaner insert/delete logic.
  • Full or partial reversal.
  • Merge two lists or k lists.

How to identify

The input involves nodes with `.next`, or the prompt asks to reverse, reorder, merge, detect a cycle, or remove nodes.

Math & Bit Manipulation

This bucket is for problems where the trick is an arithmetic property, representation detail, or binary operation.

Patterns to know

  • GCD, LCM, divisibility, modulo, and fast exponentiation.
  • XOR identities and bit masks.
  • Counting bits, powers of two, and subset representation.

How to identify

Constraints are very large, the prompt mentions modulo/divisibility, or the solution depends on binary representation.

Completed Questions

ID Question Difficulty Primary Pattern Tags Time Taken Solved
0002 Add Two Numbers Medium Linked Lists Linked List, Math, Recursion 06:36 2026-05-04
0028 Find the Index of the First Occurrence in a String Easy Arrays & Strings Two Pointers, String, String Matching 19:03 2026-05-04
0014 Longest Common Prefix Easy Trees Array, String, Trie 13:19 2026-05-04
0021 Merge Two Sorted Lists Easy Linked Lists Linked List, Recursion 13:19 2026-05-04
0009 Palindrome Number Easy Math & Bit Manipulation Math 08:51 2026-05-03
0026 Remove Duplicates from Sorted Array Easy Arrays & Strings Array, Two Pointers 08:52 2026-05-04
0027 Remove Element Easy Arrays & Strings Array, Two Pointers 19:03 2026-05-04
0013 Roman to Integer Easy Arrays & Strings Hash Table, Math, String 19:51 2026-05-03
0001 Two Sum Easy Arrays & Strings Array, Hash Table 02:19 2026-05-03
0020 Valid Parentheses Easy Design Problems String, Stack 13:19 2026-05-04