Data Structures interview questions
Practice 95 questions on data structures. Each runs in a real in-browser editor with Jest tests and a worked, diagram-backed solution.
95 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
Combine Two Sorted Linked Lists
Implement a function that merges two sorted linked lists into a single sorted linked list.
15 minAlgorithms - EASY
Difference
Implement a function that returns the elements from the first array that do not appear in the second.
15 minJavaScript - 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
Intersection
Implement a function that returns the unique values present in every input array.
15 minJavaScript - EASY
Linked List Reversal
Implement a function that reverses a singly linked list in place and returns the new head.
15 minAlgorithms - EASY
Queue
Build a queue data structure supporting enqueue, dequeue, peek, and size in FIFO order.
15 minAlgorithms - EASY
Size
Implement a function that returns the element count of any collection — array, string, object, Map, or Set.
15 minJavaScript - EASY
Sliding TTL Cache
Implement a cache whose entries expire a fixed time after their last access, not after being set.
15 minJavaScript - EASY
Stack
Build a stack data structure that supports the standard push, pop, peek, and size operations.
15 minAlgorithms - EASY
Unique Array
Implement a function that returns a new array with duplicate values removed while preserving original order.
15 minJavaScript - 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
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
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
Course Dependency
Implement a function that decides whether a set of courses can be finished given their prerequisite pairs.
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
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
Event Emitter
Implement an EventEmitter class supporting on, off, and emit to register and trigger listeners.
25 minJavaScript - MEDIUM
Event Emitter II
PREMIUMImplement an event emitter where subscribe returns a handle whose release method removes that listener.
25 minJavaScript - MEDIUM
File Explorer III
Build a file explorer that renders the tree as a flat DOM list while preserving nested visual structure.
25 minUI / FrameworksAngularReactHTML / CSS / JSVue - MEDIUM
G/PN-Counter CRDT
Build increment and decrement counters that merge by per-node maxima into a conflict-free convergent total.
25 minJavaScript - 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
Intersection By
Implement a function that intersects arrays by comparing values produced by an iteratee, keeping uniqueness.
25 minJavaScript - MEDIUM
Intersection With
Implement a function that intersects arrays using a user-supplied comparator to decide equality between elements.
25 minJavaScript - 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 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 Non-repeating Substring
Implement a function that returns the length of the longest substring containing no duplicate characters.
25 minAlgorithms - MEDIUM
LWW Register / Map CRDT
PREMIUMBuild a last-write-wins map whose entries merge by timestamp with a deterministic node-id tiebreak.
25 minJavaScript - 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 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
Memoize II
PREMIUMImplement a memoize helper that caches results for functions called with any number and type of arguments.
25 minJavaScript - MEDIUM
Mini Object-relational Mapper
Build a simplified in-memory ORM with model delegates that expose basic CRUD operations.
25 minJavaScript - MEDIUM
Mini Object-relational Mapper II
Extend a simplified in-memory ORM with richer filtering predicates and multi-field sorting.
25 minJavaScript - MEDIUM
Most Common Elements
Implement a function that returns the k most frequent integers in an array, breaking ties consistently.
25 minAlgorithms - MEDIUM
Node Registry
Implement a registry that associates values with DOM nodes without leaking memory once nodes are gone.
25 minJavaScript - MEDIUM
Normalized Entity Cache
Store entities flat by id, normalizing nested relations and merging updates immutably.
25 minJavaScript - MEDIUM
OR-Set CRDT
Build an observed-remove set where a concurrent add and remove converge with the add winning.
25 minJavaScript - 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
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
Spreadsheet
Implement a spreadsheet class that resolves numeric cell values and evaluates simple addition formulas.
25 minJavaScript - MEDIUM
Spreadsheet II
Build a spreadsheet class that evaluates left-to-right arithmetic formulas referencing other cells.
25 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
Task Coordination
Implement a function that schedules tasks with a cooldown between identical ones and returns the minimum total time.
25 minAlgorithms - MEDIUM
Test Runner II
Build a small test runner that supports nested describe suites and reports tests with their full spec names.
25 minJavaScript - MEDIUM
Test Runner III
Extend a tiny test runner with beforeEach and afterEach hooks that are inherited from outer suites.
25 minJavaScript - MEDIUM
Trie (Prefix Tree)
PREMIUMImplement a Trie data structure supporting insert, exact word search, and prefix lookup operations.
25 minAlgorithms - MEDIUM
Undo / Redo Manager
PREMIUMImplement a class that tracks value history and exposes undo and redo navigation across the timeline.
25 minJavaScript - MEDIUM
Undoable Counter
Build a counter that keeps a history of values so you can undo and redo each change.
25 minUI / FrameworksAngularReactHTML / CSS / JSVue - MEDIUM
Undoable Database
Build a user database class that supports CRUD operations plus undo and redo across the operation history.
25 minJavaScript - MEDIUM
Union By
Implement a function that returns unique values across input arrays using a custom iteratee to determine identity.
25 minJavaScript - 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
useMap
Implement a hook that wraps a JavaScript Map with set, delete, and clear helpers backed by state.
25 minJavaScript - MEDIUM
Validate Binary Search Tree
Implement a function that determines whether a binary tree satisfies the binary search tree ordering invariant.
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
Backbone Model
PREMIUMImplement a Backbone-style Model class that stores attributes and emits change events per key.
40 minJavaScript - 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
classNames II
PREMIUMExtend the classNames utility to dedupe class names and resolve function arguments lazily.
40 minJavaScript - HARD
Deep Equal
PREMIUMImplement a function that determines whether two values are structurally equal across nested objects and arrays.
40 minJavaScript - HARD
Dijkstra's Algorithm
PREMIUMImplement Dijkstra's algorithm to compute shortest paths from a source vertex in a weighted graph.
40 minAlgorithms - HARD
Drizzle Query Builder
PREMIUMBuild an in-memory query builder inspired by Drizzle with table helpers, filters, sorting, and pagination.
40 minJavaScript - HARD
Drizzle Query Builder II
PREMIUMExtend an in-memory query builder inspired by Drizzle with select projections and column aliases.
40 minJavaScript - HARD
Drizzle Query Builder III
PREMIUMExtend an in-memory query builder inspired by Drizzle with innerJoin and leftJoin between related tables.
40 minJavaScript - 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
Immer produce()
PREMIUMImplement produce so mutating a draft proxy yields a new immutable state with structural sharing.
40 minJavaScript - HARD
Mini Object-relational Mapper III
PREMIUMBuild a simplified in-memory ORM with field selection and eagerly included related records.
40 minJavaScript - 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
Observable
PREMIUMImplement a minimal Observable with subscribe/unsubscribe and of/from plus map and filter operators.
40 minJavaScript - 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
Sequence CRDT (RGA)
PREMIUMBuild a replicated growable array for text whose positional-id inserts and deletes converge across replicas.
40 minJavaScript - 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
Spreadsheet III
PREMIUMBuild a spreadsheet that recomputes dependent cells when inputs change and detects circular references.
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
Superjson
PREMIUMImplement serialize and deserialize helpers that round-trip values like Date, Map, Set, and BigInt through JSON.
40 minJavaScript - 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
Undo / Redo Manager II
PREMIUMBuild a class that tracks draft values and commits them as batch checkpoints for undo and redo navigation.
40 minJavaScript - HARD
Undoable Database II
PREMIUMBuild a user database that buffers draft mutations and commits them as batch undo and redo checkpoints.
40 minJavaScript