Data Structures & Algorithms
Complete catalog of 99 interactive algorithm visualizers. Browse by data structure category or filter by difficulty.
Add two numbers represented by linked lists in reverse digit order, simulating column-by-column addition with carry.
Simulate asteroid collisions where positive asteroids move right and negative move left. Smaller asteroids explode upon impact.
Explore the universal backtracking template: watch the state space tree expand, witness constraint pruning terminate invalid branches early, and trace how choices are systematically undone.
Determine if a binary tree is height-balanced (depth of the two subtrees of every node never differs by more than 1).
Keep score for a baseball game by processing score records, invalidations, doubling, and additions using a stack.
Count the number of permutations where either the number at position i is divisible by i, or i is divisible by the number, using recursive backtracking and divisibility pruning.
Traverse binary tree nodes level-by-level from left to right using a FIFO queue (BFS).
Find the maximum path sum along any sequence of nodes in a binary tree using bottom-up postorder DFS (ignoring negative subtrees).
Find all root-to-leaf paths in a binary tree in any order using depth-first search and backtracking.
Return the values of the nodes you can see ordered from top to bottom when standing on the right side of the binary tree.
Traverse binary tree levels alternating directions (left-to-right on even levels, right-to-left on odd levels).
Calculate the number of car fleets that will arrive at the target destination using arrival times and a monotonic stack.
An n x n matrix is valid if every row and every column contains all the integers from 1 to n (inclusive). Check validity using row and column hash sets.
Calculate distinct ways to climb n stairs using top-down memoization, filling a 1D DP table.
Visualize the recursive decision tree for climbing n stairs taking 1 or 2 steps at a time.
Find all unique combinations of candidate numbers that sum to target using recursive backtracking on the decision tree.
Find all unique combinations in candidates that sum to target. Each number may only be used once, using duplicate skipping and branch pruning.
Given two integers n and k, return all possible combinations of k numbers chosen from the range [1, n] using recursive backtracking on the decision tree.
Given an integer array nums of length n, create and return an array ans of length 2n where ans[i] == nums[i] and ans[i + n] == nums[i] for 0 <= i < n.
Find two lines that together with the x-axis form a container containing the most water using an optimal O(n) two-pointer inward scan.
Detect duplicate elements in an array using an instant-lookup hash set.
Determine if there are two distinct indices i and j such that nums[i] == nums[j] and abs(i - j) <= k using a sliding window hash set.
Count nodes in a complete binary tree in less than O(n) time by comparing left and right subtree heights.
Count the number of 'good' nodes in a binary tree (a node X is good if on the path from root to X there are no nodes with value greater than X).
Find the number of days you have to wait after the i-th day to get a warmer temperature using a monotonic decreasing stack.
Design a HashSet without using any built-in hash table libraries, demonstrating hashing (key % size) and collision resolution via separate chaining in dynamic buckets.
Compute the diameter (longest path between any two nodes) by finding max(leftDepth + rightDepth) at each node using postorder DFS.
Sort an array of 0s, 1s, and 2s in-place in linear time using Dijkstra's 3-way partitioning Dutch National Flag algorithm.
Evaluate arithmetic expressions written in Reverse Polish Notation (postfix) using a LIFO operand stack.
Find the minimum element in a sorted rotated array in O(log n) time by comparing nums[mid] to nums[right].
Generate all combinations of well-formed parentheses using recursive backtracking with open and close count pruning.
Group strings together using sorted character keys in a hash map.
Binary search to guess a secret picked number in range [1..n] in O(log n) using pre-defined guess() API feedback.
Detect whether a linked list contains a cycle using Floyd's Tortoise and Hare algorithm.
Visit binary tree nodes in Left -> Root -> Right order producing sorted order for Binary Search Trees.
Invert a binary tree by recursively swapping the left and right child subtrees of every node.
Check if two strings contain identical character frequency distributions.
Binary search on integer speed k in range [1 .. max(piles)] to find the minimum eating speed to finish all piles within h hours.
Find the kth smallest element (1-indexed) in a Binary Search Tree (BST) using in-order DFS traversal step counting.
Generate all possible letter combinations that the input phone digits could represent using keypad mapping and recursive backtracking.
Find length of longest contiguous integer streak in O(n) using a hash set.
Find the length of the longest substring containing the same letter you can get after performing at most k character replacements using a dynamic sliding window.
Find the lowest common ancestor (LCA) node of two given nodes p and q in a Binary Search Tree (BST) using value comparisons.
Find the maximum depth (height) of a binary tree by calculating 1 + max(leftDepth, rightDepth) recursively.
Calculate the maximum width among all levels of a binary tree by assigning 0-indexed position coordinates and normalizing each level against its starting index.
Sort an array of integers in ascending order using divide-and-conquer Merge Sort with O(n log n) time complexity.
Merge two sorted integer arrays into nums1 as one sorted array using two pointers and an auxiliary merge buffer.
Merge characters from word1 and word2 in alternating order, appending any remaining suffix characters.
Merge two sorted linked lists into a single sorted list by splicing together node pointers in O(n + m) time.
Find the middle node of a singly linked list using fast and slow pointers.
Complete binary min-heap implementation visualizing _heapifyUp() on insertion and _heapifyDown() on root extraction across both binary tree and 0-indexed array representations.
Design a stack supporting push, pop, top, and retrieving the minimum element in constant O(1) time using an auxiliary monotonic min-tracker stack.
Find the minimal length of a contiguous subarray of which the sum is greater than or equal to target using a dynamic sliding window.
Move all zeros in an array to the end in-place while maintaining the relative order of the non-zero elements using two pointers.
Find the next greater element for each number in nums1 within nums2 using a monotonic stack and hash map.
Find the next greater numeric element for every number in a circular integer array using a monotonic decreasing stack over two passes.
Group all nodes with odd indices together followed by nodes with even indices in O(1) space and O(n) time.
Calculate the span of stock prices in an online stream using a monotonic decreasing stack tracking [price, span] pairs.
Determine if a singly linked list is a palindrome in O(n) time and O(1) space using fast/slow pointers and in-place reversal.
Partition a string such that every substring of the partition is a palindrome using backtracking and two-pointer palindrome validation.
Partition a linked list such that all nodes less than x come before nodes greater than or equal to x, preserving relative order.
Determine if the binary tree has a root-to-leaf path such that adding up all values along the path equals targetSum.
Find all unique root-to-leaf paths where the sum of the node values equals targetSum using DFS backtracking.
Generate all possible permutations of an array of distinct integers using recursive backtracking and a visited set.
Visit binary tree nodes in Left -> Right -> Root order for bottom-up calculation and subtree evaluation.
Visit binary tree nodes in Root -> Left -> Right order using DFS recursion and call stack unwinding.
Precompute a 2D prefix sum matrix in O(m · n) time to evaluate any submatrix sum query in O(1) time using the 2D Inclusion-Exclusion Principle.
Precompute prefix sums in O(n) to evaluate contiguous subarray sum queries in constant O(1) time.
Repeatedly remove adjacent, duplicate character pairs from a string using a LIFO stack until no duplicates remain.
Delete all duplicate elements from a sorted singly linked list so each element appears only once.
Remove the n-th node from the end of the list and return its head using a one-pass two-pointer approach with a dummy node.
Reorder the list to L0 → Ln → L1 → Ln-1 → L2 → Ln-2 by finding the middle, reversing the second half, and merging both halves.
Generate all possible valid IPv4 addresses by partitioning a string into four octets (0-255 without leading zeros) using recursive backtracking.
Reverse a singly linked list iteratively in-place by reversing the next pointer of each node.
Reverse a singly linked list from position left to position right in a single pass.
Reverse a character array in-place using recursive two-pointer swap and call stack unwinding.
Rotate the linked list to the right by k places by connecting the tail to head and severing at (length - k % length).
Check if two binary trees are structurally identical and have the same node values using simultaneous DFS recursion.
Treat an m x n row-sorted matrix as a virtual 1D sorted array [0 .. m*n - 1] and perform binary search.
Find target index or insertion position in sorted array using binary search [left, right].
Find target index in a rotated sorted array in O(log n) time by finding the pivot (minimum element) and binary searching the target segment.
Binary search on candidate ship capacity in range [max(weights) .. sum(weights)] to find minimum capacity feasible within D days.
Convert an absolute Unix-style file path into its canonical simplified form using a LIFO stack to manage directory navigation, parent traversals, and redundant slashes.
Sort a linked list in O(n log n) time using top-down Merge Sort with divide-and-conquer recursion.
Square numbers and sort in O(n) time using opposing two pointers.
Generate all possible subsets (the power set) of a distinct integer array using recursive backtracking on the decision tree.
Generate all unique subsets from an integer array that may contain duplicates using sorting, duplicate skipping, and recursive backtracking.
Check if binary tree subRoot is a subtree of root with identical structure and node values.
Calculate the total sum of all numbers formed along root-to-leaf paths (each path represents a decimal number).
Swap every two adjacent nodes in a linked list and return its head without modifying node values.
Check whether a binary tree is a mirror of itself (symmetric around its center) using simultaneous dual-pointer DFS recursion.
Find all unique triplets that sum to zero with sorting and two pointers.
Find indices of two numbers that add up to target using a single-pass hash map.
Find two numbers in a 1-indexed sorted array that add up to a target number using opposing two pointers in O(n) time and O(1) space.
Determine if a string can be a palindrome after deleting at most one character using two pointers.
Determine if an input string containing '(', ')', '{', '}', '[' and ']' is valid using a LIFO stack.
Validate a 9x9 Sudoku board checking rows, columns, and 3x3 subgrids.
Determine if a binary tree is a valid Binary Search Tree (BST) where every node satisfies min < node.val < max recursively.
Determine if a target word exists in a 2D grid of characters by constructing a path of adjacent cells without reusing any cell.
