Algorithms interview questions
Practice 115 questions on algorithms. Each runs in a real in-browser editor with Jest tests and a worked, diagram-backed solution.
115 questions
- 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
Chunk
Implement a function that splits an array into groups of a given size, with the last group holding the remainder.
15 minJavaScript - EASY
Clamp
Implement a function that constrains a number to lie within an inclusive minimum and maximum range.
15 minJavaScript - 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
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
In Range
Implement a function that checks whether a number lies within a half-open range, swapping bounds when needed.
15 minJavaScript - 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
Mean
Implement a function that computes the arithmetic mean of the numbers in an array.
15 minJavaScript - 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
Range
Implement a function that builds an array of numbers from start up to end, stepping by a given increment.
15 minJavaScript - EASY
Range Right
Implement a function that builds an array of numbers from end down to start in descending order.
15 minJavaScript - EASY
Selection Sort
Implement selection sort to order an array by repeatedly picking the smallest remaining element.
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
A/B Test Bucketing
Assign users to weighted experiment variants deterministically, with a traffic gate and independent buckets per experiment.
25 minJavaScript - MEDIUM
Arithmetic Expression Evaluator
Tokenize and evaluate a math expression string with operator precedence, parentheses, and unary minus.
35 minJavaScriptGoogle · Amazon · Microsoft - MEDIUM
BigInt String Arithmetic
PREMIUMAdd and multiply arbitrarily large non-negative integers given as decimal strings, using digit-by-digit schoolbook arithmetic with carries.
25 minJavaScript - MEDIUM
Binary Search
Implement binary search on a sorted array, returning the index of the target or -1 when absent.
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
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
Connect Four
Build a two-player Connect Four game where discs fall to the lowest empty slot and four-in-a-row wins.
25 minUI / FrameworksAngularReactHTML / CSS / JSVue - 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
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
Excel Column ↔ Number
Convert between Excel column titles and numbers in both directions — A is 1, Z is 26, AA is 27 — the classic bijective base-26 system with no zero digit.
25 minJavaScript - MEDIUM
Fast Power
Raise a base to an integer exponent in logarithmic time using exponentiation by squaring, handling negative exponents.
25 minAlgorithms - MEDIUM
Feature Flag Client
PREMIUMEvaluate feature flags with targeting rules and a deterministic percentage rollout that stays sticky per user.
25 minJavaScript - 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
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 Count Connected Components
Implement a function that counts the number of connected components in an undirected graph given its edges.
25 minAlgorithms - MEDIUM
ICU Message Formatter
Parse and format ICU MessageFormat strings with plural, select, and nested argument substitution.
25 minJavaScript - 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 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
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
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
Rate Limiter
Implement a sliding-window rate limiter that decides which task timestamps fit within the allowed quota.
25 minJavaScript - 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
Roman Numerals ↔ Integer
Convert between Roman numerals and integers in both directions, handling subtractive notation like IV, IX, and XL.
25 minJavaScript - MEDIUM
Run-Length Encoding
Implement run-length encoding: compress runs of repeated characters into count+char pairs, and decode them back.
25 minJavaScript - 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
Shuffle / Sample Size
Implement lodash shuffle and sampleSize with an unbiased Fisher-Yates swap, taking an injectable RNG so shuffles are testable.
30 minJavaScript - 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
Styled Text Ranges II
Implement a function that overwrites the style on a given text range and normalizes the resulting range list.
25 minJavaScript - 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
Tic-tac-toe
Build a two-player tic-tac-toe game that detects wins and draws on a 3x3 board.
25 minUI / FrameworksAngularReactHTML / CSS / JSVue - 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
Vector Clocks
PREMIUMOrder distributed events with vector clocks, detecting whether two events are causal or concurrent.
25 minJavaScript - 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
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 Sort
PREMIUMImplement heap sort by building a max-heap and repeatedly extracting the largest element.
40 minAlgorithms - 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
Minesweeper
PREMIUMBuild Minesweeper with flood-fill reveal, flagging, and win/lose detection.
40 minUI / FrameworksAngularReactHTML / CSS / JSVue - 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
Operational Transform (Text)
PREMIUMTransform concurrent insert and delete operations so replicas converge to the same text.
40 minJavaScript - HARD
Rich Text to HTML
PREMIUMImplement a function that converts a list of styled text ranges into a canonical, properly nested HTML string.
40 minJavaScript - 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
Spreadsheet III
PREMIUMBuild a spreadsheet that recomputes dependent cells when inputs change and detects circular references.
40 minJavaScript - HARD
Statechart Engine (XState-lite)
PREMIUMBuild a state-machine engine with events, guards, entry and exit actions, and context updates.
40 minJavaScript - HARD
Styled Text Ranges
PREMIUMImplement a slice operation over text annotated with overlapping style ranges, preserving alignment.
40 minJavaScript - HARD
Styled Text Ranges III
PREMIUMImplement a function that replaces a text range and keeps the surrounding style ranges normalized.
40 minJavaScript - HARD
Styled Text Ranges IV
PREMIUMImplement a function that patches shallow style objects over a text range without clobbering unrelated keys.
40 minJavaScript - 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
Tic-tac-toe II
PREMIUMBuild a generalized tic-tac-toe game on an N x N board where M consecutive marks wins.
40 minUI / FrameworksAngularReactHTML / CSS / JSVue - 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 - HARD
Wordle
PREMIUMBuild the Wordle word-guessing game with row-by-row guesses and per-letter color feedback.
40 minUI / FrameworksAngularReactHTML / CSS / JSVue