Every solution, explained like a lesson.
A personal archive of the LeetCode problems I've solved — each one a short lesson with a live, animated walkthrough of the algorithm running on real example inputs.
Featured walkthroughs
See all →0/1 Knapsack
The 0 1 knapsack problem gives item weights and values plus a capacity, and asks for the maximum value you can carry, taking each …
3Sum
3sum finds every unique triplet in an array that sums to zero. The brute force checks all triplets in O(n³), and the duplicate han…
Best Time to Buy and Sell Stock
Best time to buy and sell stock allows exactly one purchase and one sale, and asks for the maximum profit. The sale must come afte…
Binary Tree Level Order Traversal
Binary tree level order traversal returns node values grouped by depth, one list per level. The traversal itself is a plain breadt…
Binary Tree Maximum Path Sum
Binary tree maximum path sum asks for the largest sum along any path, where a path is any sequence of connected nodes and need not…
Combination Sum
Combination sum finds every combination of candidates summing to a target, where each candidate may be reused without limit. The a…