Data structures and algorithms questions that show up in front end loops.
Progress
0 / 46 completed
Showing 46 questions
Best Time to Buy and Sell Stock
Find the largest gain from one buy followed by one later sell in a price history.
Binary Search
Find a value's index in a sorted array in logarithmic time.
Binary Search Tree
Implement a binary search tree class with insert, lookup, delete, min/max and sorted iteration.
Binary Tree Traversals
Return the pre-order, in-order and post-order traversals of a binary tree.
Breadth-First Search
Find the fewest clicks between two pages of a site with breadth-first search.
Climbing Stairs
Count the ways to reach the top taking one or two steps at a time, the gentlest intro to DP.
Coin Change
Find the fewest coins (or credit packs) that add up exactly to an amount, using dynamic programming.
Combination Sum
List every multiset of values (reuse allowed) that adds up to a target, without duplicates.
Course Schedule
Decide whether a set of lessons with prerequisites can all be completed, by detecting cycles.
Depth-First Search
Traverse a graph depth-first from a start node and return the order nodes are visited.
Group Anagrams
Bucket words that are rearrangements of each other using a canonical hash key.
Heap Sort
Sort an array in place in guaranteed O(n log n) time using a binary max-heap.
House Robber
Pick non-adjacent items to maximise their total value, a classic 1-D dynamic programming problem.
Insert Interval
Add a new booking to a sorted list of busy blocks, merging where needed, in linear time.
Insertion Sort
Sort an array in place by growing a sorted prefix one element at a time.
Kth Largest Element
Find the k-th largest value without fully sorting, using a size-k heap or quickselect.
Binary Tree Level Order Traversal
Group a tree's values by depth, row by row, using breadth-first search.
Linked List
Implement a linked list class with insertion and removal at both ends, by index, and in-place reversal.
Longest Increasing Subsequence
Find the length of the longest strictly increasing subsequence, from O(n²) DP to O(n log n) patience sorting.
Longest Substring Without Repeating Characters
Find the length of the longest run of characters with no repeats using a sliding window.
Lowest Common Ancestor
Find the closest shared ancestor of two nodes in a DOM-like tree.
Maximum Subarray
Find the contiguous stretch with the largest sum using Kadane's algorithm.
Meeting Rooms II
Find the minimum number of rooms (or calendar columns) needed so no two overlapping meetings share one.
Merge Intervals
Collapse overlapping calendar events into the minimal set of busy blocks.
Merge Sort
Sort an array of numbers with the divide-and-conquer merge sort algorithm in O(n log n).
Min Heap
Implement a binary min-heap priority queue with a custom comparator.
Non-overlapping Intervals
Drop the fewest bookings so the remaining ones never overlap.
Number of Islands
Count connected regions of filled cells in a grid with flood fill.
Permutations
Generate every ordering of a list of distinct items with backtracking.
Product of Array Except Self
For each position, compute the product of every other element without using division.
Queue
Build a first-in, first-out queue class with O(1) enqueue and dequeue.
Quick Sort
Sort an array in place with quicksort, staying fast on sorted input and heavy duplicates.
Rotate Matrix
Rotate a square grid 90° clockwise in place, like rotating an image's pixel grid.
Selection Sort
Sort an array in place by repeatedly selecting the smallest remaining element.
Serialize and Deserialize a Binary Tree
Encode a binary tree as a string and rebuild an identical tree from it.
Sliding Window Maximum
Report the peak value in every window of k consecutive samples in O(n) with a monotonic deque.
Spiral Matrix
Read a rectangular grid in clockwise spiral order using shrinking boundaries.
Stack
Build a last-in, first-out stack class, the structure behind undo history and the call stack.
Subsets
Generate the power set of a list of distinct items, such as every combination of feature flags.
Top K Frequent Elements
Return the k most frequent values in a list, faster than sorting everything.
Topological Sort
Order modules so each one comes after everything it imports, and detect circular imports.
Trie
Build a prefix tree that powers autocomplete: insert words, look them up and list completions.
Two Sum
Find the two items in a list whose values add up to a target, in a single pass with a hash map.
Valid Parentheses
Check that every bracket in a code snippet is closed by the right kind, in the right order.