YeetCode
Data Structures & Algorithms

DSA & Algorithm Deep Dives

231

Pattern-first breakdowns of classic coding interview problems: the intuition, the walkthrough, the code, and the complexity — each paired with an interactive visualizer you can step through.

Arrays13 articles

Arrays
Best Time to Buy and Sell Stock: The Running-Minimum Pattern
Solve Best Time to Buy and Sell Stock in one pass by tracking the lowest price so far — intuition, JavaScript code, a worked walkthrough, and complexity.

6 min read

Arrays
Contains Duplicate: The Hash Set Membership Pattern
Solve Contains Duplicate in O(n) with a hash set — the have-I-seen-it pattern explained with a worked walkthrough, JavaScript code, and complexity analysis.

6 min read

Arrays
Longest Consecutive Sequence: The O(n) Trick That Looks Impossible
Solve Longest Consecutive Sequence in O(n) time using a hash set and the sequence-start trick — intuition, JavaScript code, a worked walkthrough, and complexity.

6 min read

Arrays
Max Consecutive Ones: The Running-Count Pattern in One Pass
Solve Max Consecutive Ones in one linear pass with a running counter that resets on each zero — intuition, JavaScript code, a worked walkthrough, and complexity.

7 min read

Arrays
Meeting Rooms II: Counting Peak Overlap with a Sweep Line
Solve Meeting Rooms II in O(n log n) by sorting start and end times separately and sweeping for peak concurrent meetings — with a worked JavaScript walkthrough.

7 min read

Arrays
Merge Sorted Array: Merge In-Place by Filling From the Back
Merge two sorted arrays in-place with the reverse three-pointer trick — fill nums1 from the back to avoid overwriting, with a walkthrough, code, and complexity.

7 min read

Arrays
Missing Number: Find the Gap with Gauss's Sum Formula
Solve Missing Number in O(n) time and O(1) space using the Gauss sum formula — expected sum minus actual sum. Walkthrough, JavaScript code, and complexity.

6 min read

Arrays
Move Zeroes: The In-Place Two-Pointer Pattern
Move all zeroes to the end of an array in-place while keeping non-zero order — the write-pointer two-pointer solution with a walkthrough, code, and complexity.

6 min read

Arrays
Product of Array Except Self: The Prefix-Suffix Trick
Solve Product of Array Except Self in O(n) time with no division — prefix and suffix products explained with a worked walkthrough, JavaScript code, and complexity.

6 min read

Arrays
Remove Duplicates from Sorted Array: The Two-Pointer In-Place Pattern
Solve Remove Duplicates from Sorted Array in-place with two pointers — intuition, exact JavaScript code, a worked walkthrough, complexity, and common mistakes.

7 min read

Arrays
Remove Element: The Two-Pointer Overwrite Trick
Remove Element in-place with a two-pointer write scan — intuition, a worked walkthrough, JavaScript code, complexity analysis, and the common off-by-one traps.

6 min read

Arrays
Reverse String: The In-Place Two-Pointer Swap
Reverse a character array in place with two pointers — the O(n) time, O(1) space swap pattern, a worked walkthrough, JavaScript code, and common mistakes.

6 min read

Arrays
Single Number: The XOR Trick That Finds the Odd One Out
Solve Single Number in O(n) time and O(1) space using XOR — how bitwise cancellation works, a worked walkthrough, JavaScript code, and complexity analysis.

6 min read

Arrays & Hashing1 article

Backtracking12 articles

Backtracking
Combination Sum II: Pattern, Walkthrough, and JavaScript Solution
Combination Sum II explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Backtracking
Combination Sum III: Pattern, Walkthrough, and JavaScript Solution
Combination Sum III explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Backtracking
Combination Sum: Pattern, Walkthrough, and JavaScript Solution
Combination Sum explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Backtracking
Combinations: Pattern, Walkthrough, and JavaScript Solution
Combinations explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Backtracking
Letter Combinations of a Phone Number: Pattern, Walkthrough, and JavaScript Solution
Letter Combinations of a Phone Number explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Backtracking
N-Queens: Pattern, Walkthrough, and JavaScript Solution
N-Queens explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Backtracking
Palindrome Partitioning: Pattern, Walkthrough, and JavaScript Solution
Palindrome Partitioning explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Backtracking
Permutations II: Pattern, Walkthrough, and JavaScript Solution
Permutations II explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

6 min read

Backtracking
Permutations: Pattern, Walkthrough, and JavaScript Solution
Permutations explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Backtracking
Subsets II: Pattern, Walkthrough, and JavaScript Solution
Subsets II explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Backtracking
Subsets: Pattern, Walkthrough, and JavaScript Solution
Subsets explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Backtracking
Word Search: Pattern, Walkthrough, and JavaScript Solution
Word Search explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

6 min read

Binary Search
Binary Search: The O(log n) Template Every Variant Builds On
The binary search algorithm explained step by step — intuition, JavaScript code, a worked walkthrough, complexity analysis, and the off-by-one traps.

8 min read

Binary Search
Find First and Last Position of Element in Sorted Array: Binary Search That Refuses to Stop
Solve Find First and Last Position of Element in Sorted Array with two boundary binary searches — O(log n) JavaScript solution, walkthrough, and pitfalls.

8 min read

Binary Search
Find K Closest Elements: Binary Search the Answer Window
Solve Find K Closest Elements by binary-searching the best window start, with JavaScript code, a walkthrough, complexity, and tie-breaking details.

4 min read

Binary Search
Find Minimum in Rotated Sorted Array: Binary Search Without a Target
Solve Find Minimum in Rotated Sorted Array in O(log n) with pivot binary search — compare mid to the right boundary. Code, walkthrough, and pitfalls.

7 min read

Binary Search
Find Peak Element: Binary Search Without a Sorted Array
Solve Find Peak Element in O(log n) with slope binary search: why comparing mid to its right neighbor always works, plus code, a walkthrough, and pitfalls.

8 min read

Binary Search
First Bad Version: The Leftmost-True Binary Search Template
First Bad Version solved with left-boundary binary search: why right = mid keeps the answer, a worked walkthrough, JavaScript code, and complexity analysis.

7 min read

Binary Search
Guess Number Higher or Lower: Binary Search Without an Array
Solve Guess Number Higher or Lower with binary search — treat the guess API as a comparison oracle, halve the range each call, and find the pick in O(log n).

7 min read

Binary Search
Median of Two Sorted Arrays: Binary Search on the Partition
Solve Median of Two Sorted Arrays in O(log(min(m,n))) by binary searching for the correct partition — intuition, JavaScript code, a walkthrough, and complexity.

8 min read

Binary Search
Peak Index in a Mountain Array: Binary Search Without a Sorted Array
Solve Peak Index in a Mountain Array in O(log n) with slope-based binary search — intuition, JavaScript code, a full walkthrough, and common mistakes.

7 min read

Binary Search
Search in Rotated Sorted Array: Binary Search When the Order Is Broken
Solve Search in Rotated Sorted Array in O(log n) — detect which half is still sorted at every mid, keep the half that can hold the target, and halve.

8 min read

Binary Search
Single Element in a Sorted Array: Binary Search on Index Parity
Solve Single Element in a Sorted Array in O(log n) with parity binary search — the intuition, JavaScript code, a full walkthrough, and common mistakes.

8 min read

Binary Search
Sqrt(x): Binary Search on the Answer, Not the Array
Solve Sqrt(x) with binary search on the answer space — intuition, JavaScript code, a step-by-step walkthrough, complexity analysis, and overflow pitfalls.

8 min read

Binary Tree29 articles

Binary Tree
Balanced Binary Tree: One Bottom-Up Pass Instead of N Height Checks
Solve Balanced Binary Tree in O(n) with a single bottom-up DFS that measures height and checks the invariant together, with JavaScript code and a walkthrough.

8 min read

Binary Tree
Binary Tree Inorder Traversal Iterative: The curr and Stack Pattern
Learn iterative binary tree inorder traversal using a curr pointer and stack, with a full walkthrough, canonical JavaScript code, complexity, and pitfalls.

5 min read

Binary Tree
Binary Tree Inorder Traversal: Left, Root, Right Explained
Learn binary tree inorder traversal with recursive JavaScript DFS, a BST sorting trace, complexity analysis, and left-root-right intuition.

5 min read

Binary Tree
Binary Tree Level Order Traversal Without a Queue: The Recursive Trick
Solve binary tree level order traversal with DFS recursion and a level parameter — no queue needed. Intuition, JavaScript code, a worked trace, and complexity.

7 min read

Binary Tree
Binary Tree Level Order Traversal: The BFS Queue Pattern
Traverse a binary tree level by level with a BFS queue. Intuition, a worked walkthrough, JavaScript code, complexity analysis, and the levelSize trick explained.

6 min read

Binary Tree
Binary Tree Maximum Path Sum: The Postorder Gain Pattern
The postorder DFS solution to Binary Tree Maximum Path Sum, explained step by step — the bend-vs-return insight, JavaScript code, a full walkthrough, and complexity.

8 min read

Binary Tree
Binary Tree Postorder Traversal With One Stack
Iterative binary tree postorder traversal using a single stack and a lastVisited pointer — intuition, JavaScript code, a full trace, and complexity.

7 min read

Binary Tree
Binary Tree Postorder Traversal: Children Before Parents
Solve Binary Tree Postorder Traversal with recursive DFS — left, then right, then root. JavaScript solution, a worked trace, and complexity analysis.

6 min read

Binary Tree
Binary Tree Postorder Traversal: The Two-Stacks Trick
Iterative binary tree postorder traversal with two stacks, explained step by step — intuition, JavaScript code, a traced walkthrough, and complexity analysis.

7 min read

Binary Tree
Binary Tree Preorder Traversal Iterative: Master the Stack
Learn binary tree preorder traversal iteratively with a stack, including the right-before-left rule, a traced example, JavaScript code, and complexity.

5 min read

Binary Tree
Binary Tree Preorder Traversal: Root, Left, Right Explained
Learn binary tree preorder traversal with recursive JavaScript DFS, a worked trace, complexity analysis, and the root-left-right pattern.

6 min read

Binary Tree
Binary Tree Right Side View: The Right-First BFS Trick
Solve Binary Tree Right Side View with a level-order BFS that enqueues right children first — intuition, JavaScript code, a worked walkthrough, and complexity.

7 min read

Binary Tree
Binary Tree Zigzag Level Order Traversal: BFS With a Direction Flip
Solve Binary Tree Zigzag Level Order Traversal with BFS and an alternating direction flag — intuition, JavaScript code, a worked walkthrough, and complexity.

7 min read

Binary Tree
Construct Binary Tree from Preorder and Inorder Traversal
Rebuild a binary tree from its preorder and inorder arrays in O(n). The insight — preorder names the root, inorder splits left from right — with code and a trace.

7 min read

Binary Tree
Count Good Nodes in a Binary Tree: The Path-Max DFS Pattern
Count Good Nodes in a Binary Tree explained — the O(n) DFS that carries the path maximum down each root-to-node path, with a worked trace and JavaScript.

7 min read

Binary Tree
Diameter of Binary Tree: One DFS, Height and Diameter Together
Solve Diameter of Binary Tree in O(n) with a single DFS that returns height while tracking the longest through-node path — code, walkthrough, and complexity.

7 min read

Binary Tree
Invert Binary Tree: The Recursion Problem That Reveals How You Think
Invert a binary tree by recursively swapping left and right children — intuition, a worked walkthrough, JavaScript code, complexity, and common mistakes.

7 min read

Binary Tree
Lowest Common Ancestor of a Binary Tree: The Post-Order Count Method
The post-order count solution to Lowest Common Ancestor of a Binary Tree, explained with a worked walkthrough, JavaScript code, and full complexity analysis.

7 min read

Binary Tree
Maximum Depth of Binary Tree: The Bottom-Up DFS Every Tree Problem Reuses
The bottom-up DFS solution to Maximum Depth of Binary Tree, explained step by step — intuition, a worked walkthrough, JavaScript code, and complexity analysis.

7 min read

Binary Tree
Maximum Depth of Binary Tree: The Top-Down DFS Pattern
Solve Maximum Depth of Binary Tree with top-down DFS — carry depth down as a parameter and update a global max. Intuition, JavaScript code, walkthrough, complexity.

7 min read

Binary Tree
Path Sum: Root-to-Leaf DFS With a Shrinking Target
Solve Path Sum with a depth-first search that shrinks the target as it descends — intuition, JavaScript code, a worked walkthrough, and complexity analysis.

7 min read

Binary Tree
Path Sum: The Top-Down DFS Pattern for Root-to-Leaf Paths
Solve Path Sum with a top-down DFS that carries a running sum down each branch and checks it at the leaves — intuition, JavaScript code, and complexity.

8 min read

Binary Tree
Populating Next Right Pointers: The Recursive Level-Link Trick
Wire every node's next pointer in a perfect binary tree using recursion and the parent's own next pointer — intuition, JavaScript code, and a walkthrough.

7 min read

Binary Tree
Same Tree: Comparing Two Binary Trees with Recursive DFS
How to check if two binary trees are identical with recursive DFS — the base cases, JavaScript code, a worked walkthrough, complexity, and common mistakes.

7 min read

Binary Tree
Serialize and Deserialize a Binary Tree with BFS
Encode a binary tree to a string and rebuild it exactly, using level-order BFS with null sentinels — intuition, JavaScript code, a worked trace, and complexity.

7 min read

Binary Tree
Subtree of Another Tree: DFS + Same-Tree Matching
Solve Subtree of Another Tree with a clean DFS that runs a same-tree check at every node — intuition, JavaScript code, a worked walkthrough, and complexity.

7 min read

Binary Tree
Subtree of Another Tree: The Serialization Trick
Solve Subtree of Another Tree by serializing both trees to pre-order strings with null markers, then checking substring containment — code, walkthrough, complexity.

7 min read

Binary Tree
Symmetric Tree, Iteratively: Mirror Pairs in a BFS Queue
Check whether a binary tree mirrors itself without recursion. The iterative BFS-queue solution to Symmetric Tree, with a worked walkthrough, code, and complexity.

8 min read

Binary Tree
Symmetric Tree: The Mirror Recursion Pattern
Check if a binary tree is a mirror of itself with the recursive mirror pattern — intuition, JavaScript code, a worked walkthrough, and complexity analysis.

7 min read

Dynamic Programming22 articles

Dynamic Programming
Burst Balloons: The Interval DP That Rewards Thinking Backwards
The interval DP solution to Burst Balloons, explained by choosing the last balloon to burst — intuition, JavaScript code, a walkthrough, and complexity.

8 min read

Dynamic Programming
Climbing Stairs: Pattern, Walkthrough, and JavaScript Solution
Climbing Stairs explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Dynamic Programming
Coin Change II: Counting Combinations Without Double-Counting
Count the ways to make an amount from coin denominations. Coin Change II explained with the combinations DP, a worked trace, JavaScript code, and complexity.

8 min read

Dynamic Programming
Coin Change: Pattern, Walkthrough, and JavaScript Solution
Coin Change explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Dynamic Programming
Decode Ways: Memoized Recursion, JavaScript Solution, and Walkthrough
Learn Decode Ways with a memoized JavaScript dynamic programming solution, a trace of valid digit splits, complexity analysis, and zero pitfalls.

5 min read

Dynamic Programming
Edit Distance: The 2D DP Grid That Measures String Difference
The 2D dynamic programming solution to Edit Distance, explained step by step — the insert/delete/replace recurrence, a worked walkthrough, and complexity.

7 min read

Dynamic Programming
Fibonacci Number: Pattern, Walkthrough, and JavaScript Solution
Fibonacci Number explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Dynamic Programming
House Robber II: Pattern, Walkthrough, and JavaScript Solution
House Robber II explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Dynamic Programming
House Robber: Pattern, Walkthrough, and JavaScript Solution
House Robber explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Dynamic Programming
Longest Common Subsequence: The 2D DP Grid, Made Concrete
Longest Common Subsequence explained with a worked DP grid, JavaScript code, an O(n)-space rolling-row solution, complexity, and common mistakes.

8 min read

Dynamic Programming
Longest Increasing Subsequence: The 1D DP Double-Loop Pattern
Solve Longest Increasing Subsequence with bottom-up dynamic programming — the O(n²) double-loop dp array, a worked walkthrough, JavaScript code, and complexity.

8 min read

Dynamic Programming
Longest Palindromic Substring: Pattern, Walkthrough, and JavaScript Solution
Longest Palindromic Substring explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Dynamic Programming
Maximum Product Subarray: Why You Track a Min and a Max
Find the largest-product contiguous subarray in O(n) by tracking both a running max and a running min, so a negative times a negative can flip into the answer.

6 min read

Dynamic Programming
Maximum Subarray: Kadane's Algorithm, JavaScript Solution, and Walkthrough
Learn Maximum Subarray with Kadane's JavaScript algorithm, a detailed negative-prefix walkthrough, complexity comparison, and all-negative array pitfalls.

5 min read

Dynamic Programming
Min Cost Climbing Stairs: Pattern, Walkthrough, and JavaScript Solution
Min Cost Climbing Stairs explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Dynamic Programming
Min Cost to Cut a Stick: Interval DP, Explained
Solve Min Cost to Cut a Stick with interval DP — why cut order matters, the memoized recursion, a worked walkthrough, JavaScript code, and complexity.

7 min read

Dynamic Programming
Palindromic Substrings: Pattern, Walkthrough, and JavaScript Solution
Palindromic Substrings explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Dynamic Programming
Partition Equal Subset Sum: The 0/1 Knapsack in Disguise
Solve Partition Equal Subset Sum with the 0/1 knapsack subset-sum DP — intuition, a worked walkthrough, JavaScript code, and complexity analysis.

7 min read

Dynamic Programming
Regular Expression Matching: Building a Regex Engine with 2D DP
Solve LeetCode's Regular Expression Matching with a 2D dynamic programming table — the '.' and '*' rules, a worked walkthrough, JavaScript code, and complexity.

8 min read

Dynamic Programming
Super Egg Drop: The DP-Inversion Trick That Kills the O(kn²) Table
Super Egg Drop solved by flipping the question to max floors per move — a worked 2-eggs-6-floors trace, JavaScript code, and the O(k log n) complexity.

7 min read

Dynamic Programming
Unique Paths: Counting Grid Routes with 2D Dynamic Programming
Solve LeetCode Unique Paths with dynamic programming — the grid recurrence, a worked walkthrough, JavaScript code, O(m*n) complexity, and the O(n) space trick.

7 min read

Dynamic Programming
Word Break: Segmenting Strings with 1D Dynamic Programming
Solve Word Break with dynamic programming — memoized recursion and a bottom-up 1D DP table, with a worked walkthrough, JavaScript code, and complexity analysis.

7 min read

Graphs32 articles

Graphs
Alien Dictionary: Deriving Order with Topological Sort
Solve Alien Dictionary with topological sort and Kahn's algorithm: derive the alien alphabet from a sorted word list, with JavaScript code and a walkthrough.

7 min read

Graphs
All Paths From Source to Target: Backtracking Through a DAG
Enumerate every path from node 0 to node n-1 in a DAG with DFS backtracking — intuition, JavaScript code, a full walkthrough, and complexity, step by step.

7 min read

Graphs
Bellman-Ford Algorithm: Shortest Paths With Negative Weights
Bellman-Ford finds shortest paths from a source with negative edges and detects negative cycles. Intuition, JavaScript code, a walkthrough, and complexity.

8 min read

Graphs
Breadth First Search (BFS): Level-Order Graph Traversal
Learn Breadth First Search (BFS) on graphs — the queue-and-visited-set pattern, a worked walkthrough, JavaScript code, and time and space complexity.

7 min read

Graphs
Cheapest Flights Within K Stops: BFS With State, Explained
Solve Cheapest Flights Within K Stops with a level-bounded BFS that carries stop count as state — intuition, JavaScript code, a worked trace, and complexity.

8 min read

Graphs
Clone Graph: Deep-Copying a Graph Without Looping Forever
How to deep-copy an undirected graph with a BFS and a hash map — intuition, JavaScript code, a worked walkthrough, complexity, and the cycle traps to avoid.

7 min read

Graphs
Course Schedule II: Topological Sort With Kahn's Algorithm
Solve Course Schedule II with Kahn's algorithm — build in-degrees, BFS the dependency graph, detect cycles, and return a valid course order in O(V+E).

8 min read

Graphs
Course Schedule: Cycle Detection with DFS and Three Colors
Solve Course Schedule by detecting cycles in a directed graph with DFS and three visit states — intuition, JavaScript code, a worked trace, and complexity.

7 min read

Graphs
Depth First Search (DFS): Dive Deep, Then Backtrack
Learn Depth First Search on a graph — the recursive dive-and-backtrack pattern, a worked walkthrough, JavaScript code, O(V+E) complexity, and common mistakes.

8 min read

Graphs
Detect Cycle in an Undirected Graph: DFS With Parent Tracking
Detect a cycle in an undirected graph with DFS and parent tracking — the intuition, a worked walkthrough, JavaScript code, and O(V+E) complexity analysis.

7 min read

Graphs
Dijkstra's Algorithm: Shortest Paths with a Min-Heap
Dijkstra's algorithm for shortest paths on a weighted graph, explained with a min-heap — intuition, JavaScript code, a full walkthrough, and complexity.

7 min read

Graphs
Find if Path Exists in Graph: BFS on an Adjacency List
Solve Find if Path Exists in Graph by building an adjacency list and running BFS with a visited set — intuition, JavaScript code, a walkthrough, and complexity.

7 min read

Graphs
Find the City With the Smallest Number of Neighbors: Floyd-Warshall
Solve Find the City With the Smallest Number of Neighbors at a Threshold Distance using Floyd-Warshall — all-pairs shortest paths, code, and a full walkthrough.

7 min read

Graphs
Floyd-Warshall: All-Pairs Shortest Paths in Three Loops
Floyd-Warshall computes shortest paths between every pair of nodes with a triple loop and a distance matrix. Intuition, JavaScript code, walkthrough, and complexity.

7 min read

Graphs
Graph Valid Tree: Prove Connected + Acyclic with Union-Find
Check whether a set of edges forms a valid tree using Union-Find — the n-1 edge gate, cycle detection, JavaScript code, a worked walkthrough, and complexity.

7 min read

Graphs
Kahn's Algorithm: Topological Sort with BFS, Explained
Learn Kahn's algorithm for topological sort using BFS and in-degree counting — with a worked walkthrough, JavaScript code, complexity, and cycle detection.

7 min read

Graphs
Kruskal's Algorithm: Build a Minimum Spanning Tree with Union-Find
Kruskal's algorithm for the minimum spanning tree — sort edges by weight, reject cycles with union-find, add the cheapest safe edge. Code, walkthrough, complexity.

8 min read

Graphs
Max Area of Island: Grid DFS Flood Fill, Step by Step
Solve Max Area of Island with a grid DFS flood fill — sink each island as you count it, track the running maximum. Intuition, JavaScript code, and complexity.

8 min read

Graphs
Min Cost to Connect All Points: Prim's MST on a Point Cloud
The Prim's MST solution to Min Cost to Connect All Points — Manhattan-distance edges, a worked walkthrough, JavaScript code, and O(V²) complexity.

7 min read

Graphs
Network Delay Time: Dijkstra on a Weighted Directed Graph
Solve Network Delay Time with Dijkstra's algorithm — intuition, a worked priority-queue walkthrough, JavaScript code, and complexity analysis.

7 min read

Graphs
Number of Islands: The Grid DFS Flood-Fill Pattern
Count islands in a binary grid with recursive DFS flood fill — intuition, JavaScript code, a worked walkthrough, complexity analysis, and the mistakes to avoid.

7 min read

Graphs
Number of Operations to Make Network Connected: Count the Islands
Solve Number of Operations to Make Network Connected by counting connected components with BFS — feasibility check, JavaScript code, and a full walkthrough.

7 min read

Graphs
Number of Ways to Arrive at Destination: Dijkstra Meets DP
Count the shortest paths in a weighted graph by fusing Dijkstra with DP path counting — intuition, JavaScript code, a worked walkthrough, and complexity.

7 min read

Graphs
Pacific Atlantic Water Flow: Flood the Oceans, Not the Cells
Solve Pacific Atlantic Water Flow with reverse multi-source DFS from the ocean borders — intuition, JavaScript code, a worked walkthrough, and complexity.

7 min read

Graphs
Prim's Algorithm: Build a Minimum Spanning Tree Greedily
Prim's algorithm builds a minimum spanning tree by greedily adding the cheapest edge crossing out of the tree — with a walkthrough, JavaScript, and complexity.

7 min read

Graphs
Reconstruct Itinerary: Hierholzer's Algorithm for Eulerian Paths
Solve Reconstruct Itinerary with Hierholzer's algorithm — a greedy post-order DFS that walks every ticket once and rebuilds the Eulerian path in JavaScript.

8 min read

Graphs
Redundant Connection: Cycle Detection with Union-Find
Solve LeetCode Redundant Connection with Union-Find (DSU). Learn the cycle-detection insight, a worked trace, JavaScript code, and O(n·α(n)) complexity.

6 min read

Graphs
Shortest Path in an Unweighted Graph: Why BFS Just Works
Find the shortest path from a source to every node in an unweighted graph with BFS — the level-order intuition, JavaScript code, a full walkthrough, and complexity.

7 min read

Graphs
Shortest Path in Binary Matrix: BFS on an 8-Directional Grid
Solve Shortest Path in Binary Matrix with breadth-first search on an 8-directional grid — intuition, JavaScript code, a full walkthrough, and O(n²) complexity.

7 min read

Graphs
Swim in Rising Water: The Minimax Path Problem, Solved with Dijkstra
Solve Swim in Rising Water with a min-heap Dijkstra variant that minimizes the highest elevation on the path. Intuition, JavaScript, walkthrough, complexity.

8 min read

Graphs
Topological Sort with DFS: Ordering a DAG in Post-Order
Learn topological sort with DFS — order a DAG so every edge points forward, using post-order finish times, a worked walkthrough, JavaScript code, and complexity.

7 min read

Graphs
Word Ladder: BFS for the Shortest Transformation Sequence
Solve Word Ladder with BFS on an implicit word graph — intuition, a worked hit-to-cog walkthrough, JavaScript code, complexity analysis, and common mistakes.

8 min read

Greedy Algorithm16 articles

Greedy Algorithm
Assign Cookies: Pattern, Walkthrough, and JavaScript Solution
Assign Cookies explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Greedy Algorithm
Best Time to Buy and Sell Stock II: Pattern, Walkthrough, and JavaScript Solution
Best Time to Buy and Sell Stock II explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Greedy Algorithm
Candy: One Pass O(1) Space: Pattern, Walkthrough, and JavaScript Solution
Candy: One Pass O(1) Space explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Greedy Algorithm
Candy: Pattern, Walkthrough, and JavaScript Solution
Candy explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Greedy Algorithm
Car Pooling: Pattern, Walkthrough, and JavaScript Solution
Car Pooling explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Greedy Algorithm
Gas Station: Pattern, Walkthrough, and JavaScript Solution
Gas Station explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Greedy Algorithm
Hand of Straights: Pattern, Walkthrough, and JavaScript Solution
Hand of Straights explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Greedy Algorithm
Insert Interval: Pattern, Walkthrough, and JavaScript Solution
Insert Interval explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Greedy Algorithm
Jump Game II: Pattern, Walkthrough, and JavaScript Solution
Jump Game II explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Greedy Algorithm
Jump Game: Pattern, Walkthrough, and JavaScript Solution
Jump Game explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Greedy Algorithm
Lemonade Change: Pattern, Walkthrough, and JavaScript Solution
Lemonade Change explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Greedy Algorithm
Merge Intervals: Pattern, Walkthrough, and JavaScript Solution
Merge Intervals explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Greedy Algorithm
Non-overlapping Intervals: Pattern, Walkthrough, and JavaScript Solution
Non-overlapping Intervals explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Greedy Algorithm
Partition Labels: Pattern, Walkthrough, and JavaScript Solution
Partition Labels explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Greedy Algorithm
Task Scheduler: Pattern, Walkthrough, and JavaScript Solution
Task Scheduler explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Greedy Algorithm
Two City Scheduling: Pattern, Walkthrough, and JavaScript Solution
Two City Scheduling explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Hashing4 articles

Heap / Priority Queue7 articles

Heap / Priority Queue
Find Median from Data Stream: The Two-Heap Balancing Act
Solve Find Median from Data Stream with two balanced heaps — a max-heap and min-heap that keep the median at the boundary in O(log n) per insert.

6 min read

Heap / Priority Queue
Kth Largest Element in a Stream: Maintain the Cutoff
Maintain the kth largest value after every streamed add with a size-k min-heap, JavaScript code, walkthrough, complexity, and pitfalls.

6 min read

Heap / Priority Queue
Kth Largest Element in an Array: A Size-K Min-Heap
Find the kth largest array element with a size-k min-heap: JavaScript code, invariant, walkthrough, complexity, and common mistakes.

6 min read

Heap / Priority Queue
Kth Smallest in a Sorted Matrix: The Min-Heap k-Way Merge
Solve Kth Smallest Element in a Sorted Matrix with a min-heap of frontier cells — intuition, JavaScript code, a worked walkthrough, and complexity.

7 min read

Heap / Priority Queue
Last Stone Weight: Smashing Stones with a Max-Heap
Solve Last Stone Weight with a max-heap — repeatedly smash the two heaviest stones, with a worked walkthrough, JavaScript code, and complexity analysis.

7 min read

Heap / Priority Queue
Min-Heap Operations: The Data Structure Behind Every Priority Queue
How a min-heap works: insert with bubble-up, extract-min with sift-down, array index math, a worked walkthrough, JavaScript code, and complexity analysis.

8 min read

Heap / Priority Queue
Top K Frequent Elements: Keep Only K Heap Candidates
Learn Top K Frequent Elements with a frequency map and size-k min-heap, including JavaScript code, walkthrough, complexity, and heap invariants.

3 min read

Linked List20 articles

Linked List
Add Two Numbers: Pattern, Walkthrough, and JavaScript Solution
Add Two Numbers explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Linked List
Adding Nodes to a Linked List: The Traverse-to-index-1 Pattern
How to insert a node at a given index in a linked list — the traverse-to-index-1 pattern, JavaScript code, a worked walkthrough, and complexity analysis.

7 min read

Linked List
Deleting Nodes in a Linked List: The Bypass Pointer Trick
Delete a node from a linked list in O(1) once you find it by rewiring curr.next = curr.next.next — with a worked walkthrough, JavaScript, and complexity.

6 min read

Linked List
Design Linked List: Building addAtTail From head and size
Design a linked list from scratch — how head, tail, and size interact, why addAtTail walks the whole chain, JavaScript code, a walkthrough, and complexity.

6 min read

Linked List
Intersection of Two Linked Lists: Pattern, Walkthrough, and JavaScript Solution
Intersection of Two Linked Lists explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Linked List
Introduction to Linked Lists: Traversal With a Current Pointer
Learn linked list traversal from scratch — how a current pointer walks the chain node by node, why there is no random access, with JavaScript code and complexity.

7 min read

Linked List
Linked List Cycle II: Pattern, Walkthrough, and JavaScript Solution
Linked List Cycle II explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Linked List
Linked List Cycle: Pattern, Walkthrough, and JavaScript Solution
Linked List Cycle explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Linked List
LRU Cache: O(1) Get and Put With a Hash Map + Doubly Linked List
Design an LRU cache with O(1) get and put using a hash map plus a doubly linked list — intuition, JavaScript code, a full walkthrough, and complexity.

7 min read

Linked List
Merge Two Sorted Lists: Pattern, Walkthrough, and JavaScript Solution
Merge Two Sorted Lists explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Linked List
Middle of the Linked List: Pattern, Walkthrough, and JavaScript Solution
Middle of the Linked List explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Linked List
Odd Even Linked List: Pattern, Walkthrough, and JavaScript Solution
Odd Even Linked List explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Linked List
Palindrome Linked List: Pattern, Walkthrough, and JavaScript Solution
Palindrome Linked List explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Linked List
Remove Duplicates from Sorted List: Pattern, Walkthrough, and JavaScript Solution
Remove Duplicates from Sorted List explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Linked List
Remove Linked List Elements: Pattern, Walkthrough, and JavaScript Solution
Remove Linked List Elements explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Linked List
Remove Nth Node From End of List: Pattern, Walkthrough, and JavaScript Solution
Remove Nth Node From End of List explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Linked List
Reorder List: Find the Middle, Reverse, and Weave
Solve LeetCode Reorder List in O(n) time and O(1) space by finding the middle, reversing the second half, and merging both halves alternately.

7 min read

Linked List
Reverse Linked List: Pattern, Walkthrough, and JavaScript Solution
Reverse Linked List explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Linked List
Rotate List: Pattern, Walkthrough, and JavaScript Solution
Rotate List explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Linked List
Swap Nodes in Pairs: Pattern, Walkthrough, and JavaScript Solution
Swap Nodes in Pairs explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Real DSA1 article

Recursion5 articles

Sliding Window1 article

Sorting6 articles

Stacks & Queues2 articles

Stacks and Queues10 articles

Stacks and Queues
Daily Temperatures: The Monotonic Stack Pattern in One Problem
Solve Daily Temperatures with a monotonic stack in O(n) — right-to-left intuition, worked walkthrough, JavaScript code, complexity, and common mistakes.

7 min read

Stacks and Queues
Evaluate Reverse Polish Notation: The Evaluation Stack, Distilled
Evaluate Reverse Polish Notation with one stack: push numbers, pop two on each operator, and truncate division toward zero. Code, walkthrough, and complexity.

7 min read

Stacks and Queues
Implement Queue using Stacks: The Lazy Two-Stack Transfer
How to implement a queue using stacks: the two-stack lazy transfer solution in JavaScript, with an amortized O(1) proof, walkthrough, and common mistakes.

7 min read

Stacks and Queues
Implement Stack using Queues: The Queue Rotation Trick
Implement a stack using queues with the single-queue rotation trick — push enqueues then rotates size-1 elements. JavaScript code, walkthrough, complexity.

7 min read

Stacks and Queues
Min Stack: The Augmented Stack That Makes getMin O(1)
The augmented stack solution to Min Stack — store value-min pairs so getMin is O(1). Intuition, JavaScript code, a worked walkthrough, and common mistakes.

7 min read

Stacks and Queues
Next Greater Element I: The Monotonic Stack Pattern, Explained Once and For All
Solve Next Greater Element I with a monotonic stack and hash map: right-to-left scan, O(n+m) time, worked walkthrough, JavaScript code, and common mistakes.

8 min read

Stacks and Queues
Next Greater Element II: The Monotonic Stack Goes Circular
The circular monotonic stack solution to Next Greater Element II, explained: reverse-scan a doubled array, JavaScript code, walkthrough, and complexity.

8 min read

Stacks and Queues
Remove Outermost Parentheses: When a Counter Beats the Stack
Solve Remove Outermost Parentheses in O(n) with a depth counter instead of a stack — intuition, JavaScript code, a full walkthrough, and complexity.

7 min read

Stacks and Queues
Rotting Oranges: Multi-Source BFS, Where Every Layer Is a Minute
The multi-source BFS solution to Rotting Oranges, explained step by step — intuition, JavaScript code, a worked walkthrough, complexity, and common mistakes.

8 min read

Stacks and Queues
Valid Parentheses: The Stack Pattern That Unlocks Every Bracket Problem
The stack solution to Valid Parentheses, explained step by step — intuition, a worked walkthrough, JavaScript code, complexity analysis, and common mistakes.

7 min read

Strings12 articles

Strings
Find Most Frequent Vowel and Consonant: Pattern, Walkthrough, and JavaScript Solution
Find Most Frequent Vowel and Consonant explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Strings
Find Words Containing Character: Pattern, Walkthrough, and JavaScript Solution
Find Words Containing Character explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Strings
Group Anagrams: Pattern, Walkthrough, and JavaScript Solution
Group Anagrams explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Strings
Isomorphic Strings: Pattern, Walkthrough, and JavaScript Solution
Isomorphic Strings explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Strings
Jewels and Stones: Pattern, Walkthrough, and JavaScript Solution
Jewels and Stones explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Strings
Largest Odd Number in a String: Pattern, Walkthrough, and JavaScript Solution
Largest Odd Number in a String explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

6 min read

Strings
Length of Last Word: Pattern, Walkthrough, and JavaScript Solution
Length of Last Word explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Strings
Longest Common Prefix: Pattern, Walkthrough, and JavaScript Solution
Longest Common Prefix explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Strings
Reverse String II: Pattern, Walkthrough, and JavaScript Solution
Reverse String II explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Strings
Split a String in Balanced Strings: Pattern, Walkthrough, and JavaScript Solution
Split a String in Balanced Strings explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Strings
Valid Anagram: Pattern, Walkthrough, and JavaScript Solution
Valid Anagram explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Strings
Valid Palindrome: Pattern, Walkthrough, and JavaScript Solution
Valid Palindrome explained with the core pattern, a worked trace, JavaScript, complexity analysis, pitfalls, and interview-ready reasoning.

5 min read

Strings - Advanced9 articles

Strings - Advanced
Count and Say: Run-Length Encoding as a Simulation
How to generate the nth term of the Count and Say sequence with a single-pass run-length scan — intuition, JavaScript code, a worked walkthrough, and complexity.

8 min read

Strings - Advanced
Decode String: The Stack Pattern for Nested Expressions
The stack solution to LeetCode Decode String, explained step by step — expanding nested k[...] patterns in one pass with a worked walkthrough and JavaScript code.

7 min read

Strings - Advanced
Minimum Add to Make Parentheses Valid: One Greedy Pass
Solve Minimum Add to Make Parentheses Valid in one greedy pass — track two deficits, add them, done. Intuition, JavaScript code, a worked trace, and complexity.

5 min read

Strings - Advanced
Rabin-Karp: Substring Search With a Rolling Hash
The Rabin-Karp algorithm for substring search — how a rolling hash turns O(m) window comparisons into O(1), with a worked trace, JavaScript code, and complexity.

7 min read

Strings - Advanced
Rabin-Karp: Substring Search With a Rolling Hash
How Rabin-Karp finds a pattern inside text in O(n+m) average time using a rolling hash — intuition, JavaScript code, a worked walkthrough, and complexity.

6 min read

Strings - Advanced
Reorganize String: Spacing Out the Character That Dominates
Rearrange a string so no two adjacent characters match, using a frequency count and greedy even-then-odd placement — walkthrough, JavaScript code, and complexity.

6 min read

Strings - Advanced
Repeated String Match: How Many Copies Until b Fits Inside a?
Solve Repeated String Match by repeating string a until b is a substring — with the length limit that proves when to stop, a walkthrough, and JavaScript code.

7 min read

Strings - Advanced
Reverse Words in a String: Trim, Split, Reverse, Join
Reverse the word order in a string while collapsing extra whitespace — the trim/split/reverse/join pipeline in JavaScript, with a full worked walkthrough.

6 min read

Strings - Advanced
Sum of Beauty of All Substrings: Frequency Counting Done Right
Solve Sum of Beauty of All Substrings with an incremental frequency count — intuition, JavaScript code, a worked walkthrough, and O(n²·26) complexity.

7 min read

Tries1 article

Two Pointers & Sliding Window11 articles

Two Pointers & Sliding Window
3Sum: Sort First, Then Let Two Pointers Do the Work
The sorted two-pointer solution to 3Sum explained step by step — sorting, duplicate skipping, JavaScript code, a worked walkthrough, and complexity analysis.

7 min read

Two Pointers & Sliding Window
Container With Most Water: The Greedy Two Pointers Proof That Makes O(n) Obvious
Solve Container With Most Water with greedy two pointers: why moving the shorter wall is always safe, JavaScript code, a full walkthrough, and complexity.

7 min read

Two Pointers & Sliding Window
Find the Index of the First Occurrence in a String: The Substring Scan Pattern
The sliding-window solution to Find the Index of the First Occurrence in a String: JavaScript code, walkthrough, complexity, and when KMP matters.

8 min read

Two Pointers & Sliding Window
Is Subsequence: Forward Two Pointers in Their Purest Form
The forward two-pointer solution to Is Subsequence, explained step by step — greedy intuition, JavaScript code, a worked walkthrough, and complexity analysis.

7 min read

Two Pointers & Sliding Window
Longest Repeating Character Replacement: The Sliding Window Budget Check
Solve Longest Repeating Character Replacement with a sliding window and frequency count: intuition, JavaScript code, worked walkthrough, and complexity.

8 min read

Two Pointers & Sliding Window
Longest Substring Without Repeating Characters: The Sliding Window Blueprint
The O(n) sliding window solution to Longest Substring Without Repeating Characters — hash set intuition, JavaScript code, a full walkthrough, and complexity.

8 min read

Two Pointers & Sliding Window
Permutation in String: Fixed-Window Frequency Matching
Solve Permutation in String with a fixed-size sliding window and two frequency arrays — O(n) JavaScript solution, worked walkthrough, and common mistakes.

7 min read

Two Pointers & Sliding Window
Sliding Window Maximum: The Monotonic Deque That Turns O(n·k) Into O(n)
Solve Sliding Window Maximum in O(n) with a monotonic deque — the intuition, JavaScript code, a full walkthrough, complexity table, and common mistakes.

8 min read

Two Pointers & Sliding Window
Trapping Rain Water: Think in Columns, Not Pools
Solve Trapping Rain Water in O(n) with prefix max arrays: intuition, JavaScript code, worked walkthrough, complexity analysis, and common mistakes.

8 min read

Two Pointers & Sliding Window
Two Sum II: Why Sorted Input Turns a Hash Map Into Two Pointers
Solve Two Sum II with opposing two pointers — O(n) time, O(1) space on a sorted array. Intuition, JavaScript code, a full walkthrough, and pitfalls.

8 min read

Two Pointers & Sliding Window
Two Sum: The Hash Map Pattern Every Interview Builds On
The one-pass hash map solution to Two Sum, explained step by step — intuition, a worked walkthrough, JavaScript code, complexity analysis, and common mistakes.

5 min read

Keep exploring

System Design Guides

Keep exploring

AI Engineering, from Neurons to Agents