Algorithms interview questions
127 questions in Algorithms, from warm-ups to staff-level problems — solved in a real workspace with instant test feedback.
127 questions
- EASY
Balanced Brackets
Implement a function that checks whether a string of brackets is properly opened and closed in order.
15 minAlgorithms - EASY
Binary Tree Equal
Implement a function that returns whether two binary trees have identical structure and node values.
15 minAlgorithms - EASY
Binary Tree Maximum Depth
Implement a function that returns the maximum depth from root to leaf in a binary tree.
15 minAlgorithms - EASY
Bit Reversal
Implement a function that reverses the order of the bits in the binary representation of a number.
15 minAlgorithms - EASY
Bubble Sort
Implement bubble sort, repeatedly swapping adjacent out-of-order pairs until the array is sorted.
15 minAlgorithms - EASY
Combine Two Sorted Linked Lists
Implement a function that merges two sorted linked lists into a single sorted linked list.
15 minAlgorithms - EASY
Count Set Bits in a Binary Number
Implement a function that counts the number of 1 bits in the binary representation of an integer.
15 minAlgorithms - EASY
Find Duplicates in Array
Implement a function that checks whether an array contains any duplicate numbers.
15 minAlgorithms - EASY
Find Missing Number in Sequence
Implement a function that returns the single missing number from a sorted sequence of integers.
15 minAlgorithms - EASY
First Bad Version
Find the first failing version among 1..n where a monotonic isBad check flips from false to true — a boundary binary search using the fewest checks.
15 minAlgorithms - EASY
Flip Binary Tree
Implement a function that mirrors a binary tree by swapping the left and right children of every node.
15 minAlgorithms - EASY
Insertion Sort
Implement insertion sort by building the sorted portion one element at a time from the input.
15 minAlgorithms - EASY
Linked List Reversal
Implement a function that reverses a singly linked list in place and returns the new head.
15 minAlgorithms - EASY
Meeting Calendar
Implement a function that determines whether a person can attend every meeting given their time intervals.
15 minAlgorithms - EASY
Move Zeroes
Move all zeroes to the end of an array in place while keeping the non-zero elements in their original order.
20 minAlgorithmsMeta · Google - EASY
Optimal Stock Trading
Implement a function that computes the maximum profit obtainable from one buy and one sell of a stock.
15 minAlgorithms - EASY
Pair Sum
Implement a function that finds two numbers in an array that add up to a given target.
15 minAlgorithms - EASY
Queue
Build a queue data structure supporting enqueue, dequeue, peek, and size in FIFO order.
15 minAlgorithms - EASY
Roman to Integer
Convert a Roman numeral string to its integer value, handling subtractive pairs like IV and IX.
15 minAlgorithmsAmazon · Microsoft · Adobe - EASY
Selection Sort
Implement selection sort to order an array by repeatedly picking the smallest remaining element.
15 minAlgorithms - EASY
Stack
Build a stack data structure that supports the standard push, pop, peek, and size operations.
15 minAlgorithms - EASY
Staircase Climbing Combinations
Implement a function that counts the distinct ways to climb to the top of a staircase taking one or two steps.
15 minAlgorithms - EASY
String Anagram
Implement a function that determines whether two strings are anagrams of each other.
15 minAlgorithms - EASY
String Palindrome
Implement a function that returns whether a string reads the same forwards and backwards.
15 minAlgorithms - MEDIUM
0/1 Knapsack
PREMIUMMaximize the value packed into a weight-limited knapsack when each item can be taken at most once — the classic 0/1 dynamic-programming table.
25 minAlgorithms - MEDIUM
Array Product Excluding Current
Return an array where each entry is the product of every element except the one at that index, without division and in O(n).
25 minAlgorithmsAmazon · Meta · Microsoft - MEDIUM
Binary Search
Implement binary search on a sorted array, returning the index of the target or -1 when absent.
25 minAlgorithms - MEDIUM
Binary Search Tree Kth Smallest Element
Implement a function that returns the kth smallest value in a binary search tree.
25 minAlgorithms - MEDIUM
Binary Search Tree Lowest Common Ancestor
Implement a function that finds the lowest common ancestor of two nodes in a binary search tree.
25 minAlgorithms - MEDIUM
Binary Tree
Build a binary tree data structure with the essential insert, traverse, and search operations.
25 minAlgorithms - MEDIUM
Binary Tree Level Order Traversal
Implement a function that returns the values of a binary tree grouped by level from top to bottom.
25 minAlgorithms - MEDIUM
Binary Tree Rebuilding from Preorder and Inorder Traversals
Implement a function that reconstructs a binary tree given its preorder and inorder traversal sequences.
25 minAlgorithms - MEDIUM
Binary Tree Subtree
Implement a function that determines whether one binary tree appears as a subtree of another.
25 minAlgorithms - MEDIUM
Bit Counting
Implement a function that returns an array of set-bit counts for every integer from 0 up to n.
25 minAlgorithms - MEDIUM
Bloom Filter
PREMIUMBuild a Bloom filter — a compact probabilistic set that answers membership with no false negatives but possible false positives, using a bit array and several hash functions.
25 minAlgorithms - MEDIUM
Breadth-First Search
Implement breadth-first traversal of a directed graph, visiting nodes level by level from a start vertex.
25 minAlgorithms - MEDIUM
Combinations for Target Sum
Implement a function that returns every unique combination of reusable candidates that sums to a target.
25 minAlgorithms - MEDIUM
Count Islands in a Grid
Implement a function that counts the number of distinct islands of connected cells in a 2D binary grid.
25 minAlgorithms - MEDIUM
Counting / Radix Sort
Sort integers without comparisons — counting sort tallies occurrences into buckets, and radix sort applies it digit by digit from the least significant.
25 minAlgorithms - MEDIUM
Course Dependency
Implement a function that decides whether a set of courses can be finished given their prerequisite pairs.
25 minAlgorithms - MEDIUM
Decode Message
Implement a function that counts how many ways a digit string can be decoded into letters using a 1 to 26 mapping.
25 minAlgorithms - MEDIUM
Delete Nth Node from End of Linked List
Implement a function that removes the nth-from-end node from a singly linked list in one pass.
25 minAlgorithms - MEDIUM
Depth-First Search
Implement depth-first traversal of a directed graph, exploring each branch fully before backtracking.
25 minAlgorithms - MEDIUM
Deque (Double-Ended Queue)
Build a double-ended queue with constant-time push and pop at both the front and the back, backed by a doubly linked list.
25 minAlgorithms - MEDIUM
Disjoint Intervals
Implement a function that returns the minimum number of intervals to remove so the remaining ones do not overlap.
25 minAlgorithms - MEDIUM
Distinct Paths in Grid
Implement a function that counts the number of unique paths a robot can take from the top-left to bottom-right of an m by n grid.
25 minAlgorithms - MEDIUM
Edit Distance
PREMIUMCompute the minimum number of insertions, deletions, and replacements to turn one string into another — the Levenshtein distance via a 2D dynamic-programming table.
25 minAlgorithms - MEDIUM
End of Array Reachable
Implement a function that decides whether you can reach the last index of an array using each element as a max jump.
25 minAlgorithms - MEDIUM
Fast Power
Raise a base to an integer exponent in logarithmic time using exponentiation by squaring, handling negative exponents.
25 minAlgorithms - MEDIUM
Find Element in Rotated Array
Implement a function that locates a target integer in a sorted array that has been rotated at an unknown pivot.
25 minAlgorithms - MEDIUM
Find the Longest Palindromic Substring
Implement a function that returns the longest palindromic substring contained within a given string.
25 minAlgorithms - MEDIUM
Find Word in Grid
Implement a function that checks whether a target word can be traced through adjacent cells in a 2D character grid.
25 minAlgorithms - MEDIUM
GCD / LCM
Compute the greatest common divisor with Euclid's algorithm and the least common multiple, for two numbers or a whole list.
25 minAlgorithms - MEDIUM
Generate Parentheses
Generate every well-formed combination of n pairs of parentheses by backtracking — add an open bracket while any remain, and a close bracket only while it stays balanced.
25 minAlgorithms - MEDIUM
Graph Clone
Implement a function that produces a deep copy of a connected, undirected graph given a reference node.
25 minAlgorithms - MEDIUM
Graph Count Connected Components
Implement a function that counts the number of connected components in an undirected graph given its edges.
25 minAlgorithms - MEDIUM
Integer Square Root
Compute the integer square root — the floor of the real square root — using Newton's method, without Math.sqrt.
25 minAlgorithms - MEDIUM
Is the Graph a Tree
Implement a function that determines whether a given undirected graph forms a valid tree.
25 minAlgorithms - MEDIUM
Linked List
Build a singly linked list data structure with the standard insert, remove, and traversal operations.
25 minAlgorithms - MEDIUM
Linked List Detect Cycle
PREMIUMImplement a function that detects whether a singly linked list contains a cycle.
25 minAlgorithms - MEDIUM
Longest Common Subsequence
Implement a function that returns the length of the longest subsequence common to two input strings.
25 minAlgorithms - MEDIUM
Longest Consecutive Number Sequence
Implement a function that returns the length of the longest run of consecutive integers found in an unsorted array.
25 minAlgorithms - MEDIUM
Longest Increasing Subsequence
Implement a function that returns the length of the longest strictly increasing subsequence in an array.
25 minAlgorithms - MEDIUM
Longest Non-repeating Substring
Implement a function that returns the length of the longest substring containing no duplicate characters.
25 minAlgorithms - MEDIUM
Longest Repeating Substring After Replacements
Implement a function that finds the longest substring made of one repeated character allowing up to k swaps.
25 minAlgorithmsGoogle · Amazon · Meta - MEDIUM
Map With History
Implement a class that records timestamped writes and returns the most recent value at or before a queried timestamp.
25 minAlgorithms - MEDIUM
Matrix Rotation
Rotate an n×n matrix 90 degrees clockwise and return the result as a new array.
25 minAlgorithmsAmazon · Microsoft · Apple - MEDIUM
Matrix Spiral Traversal
Implement a function that walks a 2D matrix in clockwise spiral order and returns the visited values.
25 minAlgorithms - MEDIUM
Matrix Zeroing
Implement a function that zeroes out every row and column in a matrix that originally contained a zero, ideally in place.
25 minAlgorithms - MEDIUM
Maximal Square
Find the area of the largest all-ones square in a binary matrix, where each cell's square size is one more than the smallest of its top, left, and top-left neighbors.
25 minAlgorithms - MEDIUM
Maximum Product in Contiguous Array
Implement a function that finds the contiguous subarray with the largest product, handling negatives and zeros.
25 minAlgorithms - MEDIUM
Maximum Sum in Contiguous Array
Implement a function that finds the contiguous subarray with the largest sum.
25 minAlgorithms - MEDIUM
Maximum Water Trapped Between Walls
Implement a function that finds the maximum amount of water that can be trapped between two walls.
25 minAlgorithms - MEDIUM
Merge New Interval
Implement a function that inserts a new interval into a sorted list and merges any resulting overlaps.
25 minAlgorithms - MEDIUM
Merge Overlapping Intervals
Implement a function that merges all overlapping intervals in a list and returns the consolidated set in sorted order.
25 minAlgorithms - MEDIUM
Merge Sort
Implement merge sort recursively by splitting the array and merging the sorted halves back together.
25 minAlgorithms - MEDIUM
Minimum Coins for Change
Implement a function that returns the fewest coins needed to make a target amount, or -1 when no combination works.
25 minAlgorithms - MEDIUM
Minimum Meeting Rooms Needed
Implement a function that returns the fewest meeting rooms required to host a list of time intervals without conflicts.
25 minAlgorithms - MEDIUM
Minimum Path Sum
Find the cheapest path from the top-left to the bottom-right of a grid, moving only right or down, by summing each cell with the smaller of the two ways to reach it.
25 minAlgorithms - MEDIUM
Most Common Elements
Implement a function that returns the k most frequent integers in an array, breaking ties consistently.
25 minAlgorithms - MEDIUM
Neighborhood Theft
Implement a function that computes the maximum money you can rob from a row of houses without picking two adjacent ones.
25 minAlgorithms - MEDIUM
Neighborhood Theft (Circular)
Implement a function that maximizes loot from houses arranged in a circle without robbing two adjacent ones.
25 minAlgorithms - MEDIUM
Ocean Flow
Implement a function that returns every grid cell from which water can flow to both the Pacific and Atlantic oceans.
25 minAlgorithms - MEDIUM
Palindrome Partitioning
Split a string every possible way so that each piece is a palindrome — backtrack over cut positions, extending a piece only while it reads the same both ways.
25 minAlgorithms - MEDIUM
Palindromic Substrings
Implement a function that counts every palindromic substring within a string, including overlapping occurrences.
25 minAlgorithms - MEDIUM
Partition Equal Subset Sum
Decide whether an array can split into two subsets with equal sums — a subset-sum dynamic-programming problem over half the total.
25 minAlgorithms - MEDIUM
Permutations & Subsets
PREMIUMGenerate every permutation and every subset of an array with the same backtracking template — choose, recurse, and undo.
25 minAlgorithms - MEDIUM
Phone Letter Combinations
List every letter string a phone number could spell, mapping each digit to its keypad letters and backtracking through the choices.
25 minAlgorithms - MEDIUM
Prime Check / Sieve
Test whether a number is prime and generate all primes up to n with the Sieve of Eratosthenes.
25 minAlgorithms - MEDIUM
Queue via Two Stacks
Build a FIFO queue out of two LIFO stacks — pour one stack into the other so the reversed order dequeues oldest-first in amortized constant time.
25 minAlgorithms - MEDIUM
Quick Sort
Implement quick sort recursively, partitioning around a pivot and sorting each side independently.
25 minAlgorithms - MEDIUM
Quickselect
PREMIUMFind the k-th smallest element of an unsorted array in average linear time by partitioning, without fully sorting it.
25 minAlgorithms - MEDIUM
Reading Order
Implement a function that sorts positioned canvas elements into natural left-to-right, top-to-bottom reading order.
25 minAlgorithms - MEDIUM
Reading Order II
Implement a function that groups misaligned 2D canvas elements into rows, then sorts them into a natural reading order.
25 minAlgorithms - MEDIUM
Rearrange Linked List
Implement a function that reorders a singly linked list by interleaving nodes from the front and the reversed back half.
25 minAlgorithms - MEDIUM
Search a 2D Matrix
Search a matrix whose rows and columns are both sorted by walking a staircase from the top-right corner, eliminating a whole row or column at each step.
25 minAlgorithms - MEDIUM
Segment Words
Implement a function that decides whether a string can be broken into a sequence of words from a given dictionary.
25 minAlgorithmsAmazon · Google · Meta - MEDIUM
Smallest Element in Rotated Sorted Array
Implement a function that finds the minimum value in a sorted array that has been rotated at an unknown pivot.
25 minAlgorithms - MEDIUM
String Anagram Groups
Implement a function that groups an array of strings so anagrams of each other end up in the same bucket.
25 minAlgorithms - MEDIUM
Sum Without Addition
Implement a function that adds two integers using only bitwise operators, without using + or -.
25 minAlgorithms - MEDIUM
Task Coordination
Implement a function that schedules tasks with a cooldown between identical ones and returns the minimum total time.
25 minAlgorithms - MEDIUM
Trie (Prefix Tree)
PREMIUMImplement a Trie data structure supporting insert, exact word search, and prefix lookup operations.
25 minAlgorithms - MEDIUM
Triplet Sum
Implement a function that returns every unique triplet of distinct indices whose values sum to zero.
25 minAlgorithms - MEDIUM
Union-Find (Disjoint Set)
PREMIUMBuild a disjoint-set structure with near-constant-time union and find, using path compression and union by rank to keep the trees flat.
25 minAlgorithms - MEDIUM
Validate Binary Search Tree
Implement a function that determines whether a binary tree satisfies the binary search tree ordering invariant.
25 minAlgorithms - MEDIUM
Weighted Random Pick
Pick items at random in proportion to their weights using prefix sums and a binary search, with an injectable RNG so picks are testable.
25 minAlgorithms - MEDIUM
Word Finder
Implement a data structure that supports adding words and searching with a wildcard character that matches any letter.
25 minAlgorithms - HARD
Binary Search Tree
PREMIUMBuild a binary search tree with insert, search, and delete operations preserving the BST invariant.
40 minAlgorithms - HARD
Binary Tree Maximum Total Path
PREMIUMImplement a function that returns the maximum sum of node values along any path in a binary tree.
40 minAlgorithms - HARD
Binary Tree Serialization and Deserialization
PREMIUMImplement functions that convert a binary tree to a string and reconstruct the same tree back from that string.
40 minAlgorithms - HARD
Dijkstra's Algorithm
PREMIUMImplement Dijkstra's algorithm to compute shortest paths from a source vertex in a weighted graph.
40 minAlgorithms - HARD
Extraterrestrial Language
PREMIUMGiven words sorted in an unknown alphabet's order, reconstruct the alphabet.
40 minAlgorithmsGoogle · Airbnb · Facebook - HARD
Fenwick Tree (Binary Indexed Tree)
PREMIUMBuild a Fenwick tree for logarithmic prefix-sum queries and point updates, using the lowest-set-bit trick to walk responsibility ranges.
40 minAlgorithms - HARD
Find Words in Grid
PREMIUMImplement a function that returns every word from a dictionary that can be traced through adjacent cells in a grid.
40 minAlgorithms - HARD
Heap
PREMIUMImplement a binary heap data structure supporting push, pop, peek, and heapify with the standard ordering invariant.
40 minAlgorithms - HARD
Heap Sort
PREMIUMImplement heap sort by building a max-heap and repeatedly extracting the largest element.
40 minAlgorithms - HARD
Linked Lists Combine K Sorted
PREMIUMMerge k pre-sorted singly-linked lists into one sorted list in O(n log k) time.
40 minAlgorithmsGoogle · Amazon · Meta - HARD
Median of Two Sorted Arrays
PREMIUMFind the median of two sorted arrays in logarithmic time by binary-searching for the partition that splits all the elements into equal halves.
40 minAlgorithms - HARD
N-Queens
PREMIUMPlace N queens on an N×N board so none attack another — a classic backtracking search that places one queen per row and prunes column and diagonal conflicts.
40 minAlgorithms - HARD
Number Stream Median
PREMIUMImplement a data structure that ingests integers one at a time and reports the running median in logarithmic time.
40 minAlgorithms - HARD
Persistent Immutable List
PREMIUMBuild an immutable list where every update returns a new version that shares unchanged nodes with the old one — structural sharing over a cons list.
40 minAlgorithms - HARD
Segment Tree
PREMIUMBuild a segment tree over an array for logarithmic range-sum queries and point updates, each tree node holding the aggregate of its slice.
40 minAlgorithms - HARD
Shortest Substring Containing Characters
PREMIUMImplement a function that returns the smallest window of a string that contains every character of another string.
40 minAlgorithms - HARD
Skip List
PREMIUMBuild a skip list — a sorted set layered with express lanes of linked lists so search, insert, and delete run in expected logarithmic time.
40 minAlgorithms - HARD
Sudoku Solver
PREMIUMFill a 9×9 Sudoku grid by backtracking — try each digit in the next empty cell, checking its row, column, and 3×3 box, and undo on a dead end.
40 minAlgorithms - HARD
Topological Sort
PREMIUMImplement a function that returns a topological ordering of nodes in a directed acyclic graph.
40 minAlgorithms - HARD
Wildcard Matching
PREMIUMDecide whether a string matches a pattern containing `?` (any single character) and `*` (any sequence) — a two-dimensional dynamic-programming match over string and pattern.
40 minAlgorithms