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 →Two Sum
We are hunting for a pair that sums to the target. The brute-force instinct is to try every pair, but that repeats a lot of work. …
Best Time to Buy and Sell Stock
Profit on any day equals today's price minus the cheapest price seen so far. We never need to know the future — only the lowest pr…
Maximum Subarray
At each position, ask one local question: does the running sum still help me, or is the current element better on its own? If the …
3Sum
Sorting unlocks two tricks: it lets a left/right pointer pair converge by sum, and it groups duplicates together so we can skip th…
Longest Substring Without Repeating Characters
Keep a window that holds only distinct characters. As the right edge moves forward, if it hits a character already inside the wind…
Valid Parentheses
Brackets nest last-opened, first-closed — exactly a stack. Push each opener; when a closer arrives, the bracket on top must be its…