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
Trying every triple is O(n³). It drops to O(n²) by turning it into many small Two Sum problems on a sorted array. Fix the first nu…
Best Time to Buy and Sell Stock
Instead of asking which pair of days is best, ask a question about each day on its own: if I sell today, what is the most I can ma…
Binary Tree Level Order Traversal
BFS works here because a queue hands nodes back in the order they arrived, and children are pushed while their parents are being r…
Binary Tree Maximum Path Sum
Every path has exactly one highest node, where it bends: up one side, through that node, down the other. So the answer is the best…
Combination Sum
Think of the answer as a search tree. The root is the target, each edge subtracts one candidate, and each node records how much is…