Visualizer
373 walkthroughs. One step at a time.
Each page runs a real algorithm and shows the pointers, cells and variables changing with a caption for every step. Pick a topic, press play, then solve the same problem in the editor.
Want the patterns behind them? See the 27 interview patterns or trace your own code.
Arrays (34)
- 3Sum
- Array Leaders
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock II
- Check if Array Is Sorted and Rotated
- Chocolate Distribution Problem
- Container With Most Water
- Contains Duplicate
- Count Subarrays with given XOR
- Find Minimum in Rotated Sorted Array
- Find the Duplicate Number
- Kadane's Algorithm
- Kth Largest Element in an Array
- Longest Consecutive Sequence
- Longest Subarray with Sum K
- Majority Element
- Majority Element II
- Maximum Product Subarray
- Merge Sorted Array
- Min and Max in Array
- Missing And Repeating
- Missing And Repeating (Arrays)
- Next Permutation
- Pascal's Triangle
- Product of Array Except Self
- Rearrange Array Elements by Sign
- Reverse Array
- Rotate Array
- Search in Rotated Sorted Array
- Sort Colors
- Sort Colors (Arrays)
- Subarray Sum Equals K
- Trapping Rain Water
- Two Sum
BST (21)
- Binary Search Tree to Greater Sum Tree
- Binary Tree to DLL
- BST Search
- Ceil in BST
- Construct Binary Search Tree from Preorder Traversal
- Delete Node in a BST
- Floor in BST
- Inorder Successor in BST
- Insert into a Binary Search Tree
- k-th Smallest in BST
- Kth Largest Element in a BST
- Kth Smallest Element in a BST
- Largest BST Subtree
- Lowest Common Ancestor of a Binary Search Tree
- Merge Two BSTs
- Recover Binary Search Tree
- Recover Binary Search Tree (Swap Nodes)
- Two Sum IV - Input is a BST
- Unique Binary Search Trees
- Unique Binary Search Trees II
- Validate Binary Search Tree
Backtracking (13)
Binary Search (16)
- Allocate Minimum Pages
- Capacity To Ship Packages Within D Days
- Find Peak Element
- Find the Smallest Divisor Given a Threshold
- Halve the search space
- Implement Lower Bound
- Koko Eating Bananas
- Magnetic Force Between Two Balls
- Median of Two Sorted Arrays
- Minimum Number of Days to Make m Bouquets
- Row with Max 1s in Rowwise Sorted
- Search Insert Position
- Single Element in a Sorted Array
- Split Array Largest Sum
- Sqrt(x)
- The Painter's Partition Problem-II
Binary Trees (32)
- All Nodes Distance K in Binary Tree
- Balanced Binary Tree
- Binary Tree Cameras
- Binary Tree Inorder Traversal
- Binary Tree Inorder Traversal (Binary Trees)
- Binary Tree Level Order Traversal
- Binary Tree Maximum Path Sum
- Binary Tree Postorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Right Side View
- Binary Tree Zigzag Level Order Traversal
- Bottom View of Binary Tree
- Burning Tree
- Children Sum in a Binary Tree
- Construct Binary Tree from Inorder and Postorder Traversal
- Construct Binary Tree from Preorder and Inorder Traversal
- Count Complete Tree Nodes
- Count Good Nodes in Binary Tree
- Diameter of Binary Tree
- Flatten Binary Tree to Linked List
- Invert Binary Tree
- Isomorphic Trees
- Lowest Common Ancestor of a Binary Tree
- Maximum Depth of a Binary Tree
- Path Sum
- Same Tree
- Serialize and Deserialize Binary Tree
- Subtree of Another Tree
- Sum Root to Leaf Numbers
- Symmetric Tree
- Top View of Binary Tree
- Vertical Order Traversal of a Binary Tree
Bit Manipulation (11)
Dynamic Programming (50)
- 0 - 1 Knapsack Problem
- Best Time to Buy and Sell Stock III
- Best Time to Buy and Sell Stock IV
- Best Time to Buy and Sell Stock with Cooldown
- Best Time to Buy and Sell Stock with Transaction Fee
- Boolean Parenthesization
- Burst Balloons
- Cherry Pickup II
- Climbing Stairs
- Coin Change
- Coin Change II
- Combination Sum IV
- Count Square Submatrices with All Ones
- Count Subsets with Sum
- Decode Ways
- Delete Operation for Two Strings
- Distinct Subsequences
- Edit Distance
- Frog Jump
- House Robber
- House Robber II
- Jump Game II
- Knapsack with Duplicate Items
- Longest Arithmetic Subsequence
- Longest Bitonic Subsequence
- Longest Common Subsequence
- Longest Increasing Subsequence
- Longest Palindromic Subsequence
- Longest String Chain
- Matrix Chain Multiplication
- Max Sum of Non-Adjacent Elements
- Maximal Rectangle (Dynamic Programming)
- Maximum Sum Submatrix
- Minimum Falling Path Sum
- Minimum Insertion Steps to Make a String Palindrome
- Minimum Path Sum
- N-th Tribonacci Number
- Number of Longest Increasing Subsequence
- Palindrome Partitioning II
- Partition Equal Subset Sum
- Regular Expression Matching
- Rod Cutting
- Shortest Common Supersequence
- Subset Sum Problem
- Triangle
- Unique Paths
- Unique Paths (DP on Grid)
- Unique Paths II
- Wildcard Matching
- Word Break
Graph (49)
- Accounts Merge
- Alien Dictionary
- Articulation Point
- Bellman-Ford Algorithm
- Cheapest Flights Within K Stops
- Clone Graph
- Count Strongly Connected Components
- Count Unreachable Pairs of Nodes in an Undirected Graph
- Course Schedule
- Course Schedule (Prerequisite Tasks)
- Course Schedule (Prerequisite Tasks)
- Course Schedule II
- Critical Connections in a Network
- Dijkstra Algorithm
- Directed Graph Cycle
- Find Eventual Safe States
- Find the City with Fewest Reachable Neighbors
- Flood Fill
- Floyd Warshall
- Graph Valid Tree
- Is Graph Bipartite?
- Making A Large Island
- Maximum Connected with One Change
- Maximum Stone Removal
- Min Cost to Connect All Points
- Minimum Number of Days to Disconnect Island
- Minimum Spanning Tree (Kruskal's)
- Minimum Spanning Tree (Prim's)
- Most Stones Removed with Same Row or Column
- Network Delay Time
- Number of Connected Components in an Undirected Graph
- Number of Islands
- Number of Islands II
- Number of Provinces
- Pacific Atlantic Water Flow
- Path With Minimum Effort
- Redundant Connection
- Rotting Oranges
- Shortest Path in Directed Acyclic Graph
- Shortest Path in Unweighted Graph
- Surrounded Regions
- Swim in Rising Water
- Topological Sort (BFS - Kahn's)
- Topological Sort (DFS)
- Topological Sort (Kahn's Algorithm)
- Undirected Graph Cycle
- Walls and Gates
- Word Ladder
- Word Ladder II
Greedy (15)
- Activity Selection
- Activity Selection (N Meetings)
- Assign Cookies
- Fractional Knapsack
- Gas Station
- Hand of Straights
- Job Sequencing Problem
- Jump Game
- Largest Number
- Lemonade Change
- Merge Triplets to Form Target Triplet
- Minimum Number of Arrows to Burst Balloons
- Minimum Platforms
- Partition Labels
- Valid Parenthesis String
Heap (14)
- Design Twitter
- Design Twitter
- Find Median from Data Stream
- IPO
- K Closest Points to Origin
- K-th Largest Sum Contiguous Subarray
- Kth Largest Element in a Stream
- Last Stone Weight
- Minimum Cost to Connect Sticks
- Reorganize String
- Sort Characters By Frequency
- Task Scheduler
- Top K Frequent Elements
- Top K Frequent Words
Intervals (5)
Linked List (17)
- Add Two Numbers
- Copy List with Random Pointer
- Cycle Detection
- Delete Node in a Linked List
- Flatten a Multilevel Doubly Linked List
- Intersection of Two Linked Lists
- LRU Cache
- Merge k Sorted Lists
- Merge Two Sorted Lists
- Middle of the Linked List
- Palindrome Linked List
- Remove Nth Node From End of List
- Reorder List
- Reverse Linked List II
- Rotate List
- Swap Nodes in Pairs
- Three-pointer reversal
Math (11)
Matrix (6)
Queue (5)
Recursion (7)
Sliding Window (9)
Sorting (7)
Stack (15)
Strings (21)
- Count and Say
- Encode and Decode Strings
- Find the Index of the First Occurrence in a String
- Find the Index of the First Occurrence in a String (Pattern Matching)
- Group Anagrams
- Integer to Roman
- Isomorphic Strings
- Longest Common Prefix
- Longest Palindromic Substring
- Longest Repeating Character Replacement
- Minimum Window Substring
- Palindromic Substrings
- Permutation in String
- Repeated String Match
- Reverse Words in a String
- Roman to Integer
- Search Pattern (Rabin-Karp Algorithm)
- String to Integer (atoi)
- Valid Anagram
- Valid Palindrome
- Z-Algorithm
