Series

LeetCode

Sep 13, 2022 LeetCode Patterns 15 min read

LeetCode Patterns: Greedy Algorithms

When does picking the locally best option give the global optimum? A working tour of greedy algorithms with proofs (exchange argument), classic problems (Jump Game, Gas Station, Interval Scheduling, Task Scheduler, …

Aug 29, 2022 LeetCode Patterns 16 min read

LeetCode Patterns: Stack and Queue

Master stack and queue applications: valid parentheses, monotonic stack for next greater element, BFS with queues, priority queues for top-K problems, and deque for sliding window maximum.

Aug 14, 2022 LeetCode Patterns 18 min read

LeetCode Patterns: Backtracking Algorithms

Master the universal backtracking template through six classic problems: Permutations, Combinations, Subsets, Word Search, N-Queens, and Sudoku Solver. Learn the choose -> recurse -> un-choose pattern and the pruning …

Jul 30, 2022 LeetCode Patterns 16 min read

LeetCode Patterns: Dynamic Programming Basics

Master dynamic programming through a single recipe: define the state, write the transition, anchor the base case. Worked solutions for Climbing Stairs, House Robber, Coin Change, LIS, 0/1 Knapsack, LCS, and Edit …

Jul 15, 2022 LeetCode Patterns 16 min read

LeetCode Patterns: Binary Tree Traversal and Construction

A unified mental model for binary trees: how the four traversal orders are really one DFS recipe, why recursion and an explicit stack are the same algorithm, and how to reconstruct a tree from preorder + inorder. …

Jun 30, 2022 LeetCode Patterns 17 min read

LeetCode Patterns: Binary Search

A working coder's guide to binary search: three templates, rotated arrays, peak finding, and binary search on the answer with worked traces and figures.

Jun 15, 2022 LeetCode Patterns 13 min read

LeetCode Patterns: Sliding Window Technique

Master fixed-size and variable-size sliding window patterns. Solve Maximum Sum Subarray, Longest Substring Without Repeating Characters, Minimum Window Substring, and Permutation in String.

May 31, 2022 LeetCode Patterns 15 min read

LeetCode Patterns: Linked List Operations

A complete linked list toolkit: reversal (iterative and recursive), merging sorted lists, Floyd's cycle detection, removing the nth node from end, and an LRU cache built on a doubly linked list plus hash map.

May 16, 2022 LeetCode Patterns 15 min read

LeetCode Patterns: Two Pointers

A deep tour of the two-pointer family: collision, fast/slow, sliding window, and partition pointers. Five problems (Two Sum II, 3Sum, Container With Most Water, Linked List Cycle, Move Zeroes) explained with invariants, …

May 1, 2022 LeetCode Patterns 13 min read

LeetCode Patterns: Hash Tables

Master hash table patterns through four classic LeetCode problems — Two Sum, Group Anagrams, Longest Substring Without Repeating Characters, and Top K Frequent Elements. Learn complement search, canonical-form grouping, …