Prep Room
Resources
Resume
JD
Your Jobs
Upskill
Contests
How it works
Demo
VS Code extension
Pricing
Sign in
Start free
Resources
/
Coding
Coding
questions.
79 coding questions from the bank, ready to practice out loud.
Practice coding
All 79 questions
Minimum meeting rooms required
Write a function that takes a list of meeting intervals and returns the minimum number of rooms required to schedule all of them.
Data Structures
Mid–senior
Add to study plan
Longest substring without repeats
Given a string, return the length of the longest substring without repeating characters. Your function should run in linear time.
Algorithms
Entry–mid
Add to study plan
Least-recently-used cache implementation
Implement a least-recently-used cache with constant-time get and put. The capacity is fixed at construction.
Data Structures
Mid–senior
Add to study plan
Running median from integer stream
Write a function that takes a stream of integers and returns the running median after each insert.
System Reasoning
Senior–staff+
Add to study plan
Counting distinct islands in grid
Given a 2D grid of 1s and 0s representing land and water, return the number of distinct islands. Two cells are part of the same island if they share an edge.
Algorithms
Entry–mid
Add to study plan
Pairs summing to target
You have an array of integers and need to find every pair that sums to a given target. Optimize for time and call out the trade-off you're making.
Optimization
Entry–mid
Add to study plan
Binary tree serialization
Implement a function that serializes and deserializes a binary tree. Pick the format and explain why it works for your traversal.
Data Structures
Mid–senior
Add to study plan
Grouping anagrams together
Given a list of words, group anagrams together. Each group is a list of words; order within groups doesn't matter.
Algorithms
Entry–mid
Add to study plan
Rate limiter for multiple users
Design a rate limiter that allows N requests per user per minute. Implement the check function and discuss how you'd handle a million users.
System Reasoning
Mid–senior
Add to study plan
Fixing stack overflow in recursion
Here's a recursive function that's supposed to flatten a nested list of integers but is throwing stack overflow on large inputs. How would you fix it?
Debugging
Mid–senior
Add to study plan
Maximum profit two transactions
Given an array of stock prices indexed by day, return the maximum profit from at most two non-overlapping buy-sell transactions.
Algorithms
Mid–senior
Add to study plan
Trie with prefix search
Implement a trie that supports insert, search, and prefix-search of words. Then write a function that returns all words sharing a given prefix.
Data Structures
Mid–senior
Add to study plan
Top K IPs from logs
Write a function that processes a log file and returns the top K most frequent IP addresses. Assume the file is too large to fit in memory.
System Reasoning
Senior–staff+
Add to study plan
Right side view of tree
Given a binary tree, return the values you'd see standing on the right side. Each level contributes at most one value.
Algorithms
Entry–mid
Add to study plan
Optimizing kth largest element search
You have a function that finds the kth largest element by sorting. The interviewer asks you to do better — what's your move and what's the worst case?
Optimization
Mid–senior
Add to study plan
Implementing a queue with stacks
Implement a queue using only stacks. Both enqueue and dequeue should be amortized O(1).
Data Structures
Entry–mid
Add to study plan
Detecting cycles in directed graphs
Given a directed graph as an adjacency list, detect whether it has a cycle. Return true or false.
Algorithms
Mid–senior
Add to study plan
Thread-safe username availability checker
Implement a function that returns the next available username given a desired one, appending numbers if needed. Multiple workers will call this concurrently — make it safe.
System Reasoning
Senior–staff+
Add to study plan
Reversing a 32-bit signed integer
Given a 32-bit signed integer, reverse its digits and return the result. If the reversed integer overflows, return zero.
Algorithms
Entry–mid
Add to study plan
Implementing a min-stack
Implement a min-stack that supports push, pop, and an O(1) operation that returns the current minimum.
Data Structures
Entry–mid
Add to study plan
Kth most frequent word
Given a long string of words separated by spaces, return the kth most frequent word. If multiple words tie, return the alphabetically smallest.
Optimization
Mid–senior
Add to study plan
One edit distance check
Implement a function that returns whether two strings are one edit away — insert, delete, or replace one character.
Algorithms
Entry–mid
Add to study plan
Memoizing with a freshness window
You're given a function that fetches a user's profile from a remote service. Implement a memoized version that respects a 5-minute freshness window.
System Reasoning
Mid–senior
Add to study plan
Triplets summing to zero
Given an array, return all distinct triplets whose values sum to zero. The result should not contain duplicate triplets.
Algorithms
Mid–senior
Add to study plan
Range query data structure
Design a class that stores a stream of integers and lets callers ask for the number of values within a given range. Inserts and range queries should both be fast.
Data Structures
Senior–staff+
Add to study plan
Longest increasing path in grid
You have an N-by-N grid. Write a function that returns the longest increasing path you can walk through adjacent cells in any direction.
Optimization
Senior–staff+
Add to study plan
Merge sorted linked lists bug
Here's a function that's supposed to merge two sorted linked lists into one. It works on most inputs but returns the wrong result when one list is empty. Walk me through your fix.
Debugging
Entry–mid
Add to study plan
Palindrome linked list check
Write a function that returns whether a singly linked list is a palindrome. Optimize for space.
Algorithms
Mid–senior
Add to study plan
Binary search tree in-order iterator
Implement a function that takes the root of a binary search tree and returns an iterator that yields values in order. The iterator should use O(h) space.
Data Structures
Senior–staff+
Add to study plan
Words from one keyboard row
Given a list of words, find all words that can be typed using only one row of a QWERTY keyboard. Define the rows yourself.
Algorithms
Entry–mid
Add to study plan
Parsing ISO 8601 duration strings
Write a function that parses an ISO 8601 duration string like 'PT1H30M' and returns total minutes. Handle missing components and call out malformed inputs.
System Reasoning
Entry–mid
Add to study plan
Intersection of large sets
You need to find whether two sets of integers have any element in common. The sets can be very large. Walk me through your choice of approach.
Optimization
Entry–mid
Add to study plan
Counting subarrays with target sum
Given an array of integers and an integer k, return the number of contiguous subarrays whose sum equals k.
Algorithms
Mid–senior
Add to study plan
Clustering strings by edit distance
Implement a function that takes a list of strings and groups them into clusters where strings in the same cluster differ by at most one character.
Data Structures
Senior–staff+
Add to study plan
Finding nested keys by predicate
Write a function that takes a JSON-like nested structure and returns all key paths whose value matches a predicate. Don't assume a fixed depth.
System Reasoning
Mid–senior
Add to study plan
Merging overlapping intervals
Given a list of intervals, merge all overlapping ones and return the result sorted by start time.
Algorithms
Entry–mid
Add to study plan
Hash table with open addressing
Implement a hash table from scratch with open addressing. Support insert, lookup, and delete with linear probing.
Data Structures
Senior–staff+
Add to study plan
Concurrent API calls with limit
You have a method that calls a third-party API for each item in a list. Rewrite it so that calls run concurrently with a maximum of N in flight at any time.
Optimization
Mid–senior
Add to study plan
Validating nested parentheses
Given a string of parentheses, brackets, and braces, return true if they're correctly nested and matched.
Algorithms
Entry–mid
Add to study plan
Exponential backoff with jitter
Implement an exponential backoff helper for an HTTP client. It should accept a callable, a max-retry count, and a base delay, and add jitter.
System Reasoning
Mid–senior
Add to study plan
Maximum in sliding window
Given an array of integers and a window size k, return the maximum of every contiguous window in a single pass. Sorting each window is too slow — what structure gets you O(n) total?
Algorithms
Mid–senior
Add to study plan
Task scheduling with dependencies
You're given build tasks and their dependencies. Tasks with no unmet dependencies can run in parallel. Write a function that returns the minimum number of rounds needed to finish everything, or reports that it's impossible.
Algorithms
Mid–senior
Add to study plan
In-memory store with nested transactions
Implement an in-memory key-value store that supports get, set, and nested transactions: begin, commit, and rollback. A rollback undoes everything since the matching begin.
Data Structures
Senior–staff+
Add to study plan
Merging K sorted iterators
You have K sorted iterators that are too large to materialize. Write a function that yields all their elements in sorted order, doing O(log K) work per element.
Data Structures
Mid–senior
Add to study plan
Consistent hashing ring implementation
Implement a consistent-hashing ring: add a node, remove a node, and look up which node owns a key. Show why only a small fraction of keys move when membership changes.
System Reasoning
Senior–staff+
Add to study plan
Debounce wrapper for expensive functions
Write a debounce wrapper: given an expensive function and a delay, return a version that only fires after calls stop arriving for that delay. What happens to the arguments and return value of the suppressed calls?
System Reasoning
Mid–senior
Add to study plan
Minimum capacity for job deadlines
You must process N jobs of known sizes within D days, doing jobs in order, one batch per day. Write a function that finds the minimum daily capacity that makes the deadline. What's the search space?
Optimization
Mid–senior
Add to study plan
Diffing nested configuration objects
Write a function that diffs two nested configuration objects and returns the minimal change set: paths added, removed, and changed. Arrays and scalars can appear at any depth.
System Reasoning
Mid–senior
Add to study plan
Binary search infinite loop bugs
A binary search implementation returns correct answers on most inputs but loops forever on a few. Without seeing the code, what are the classic mistakes that cause this, and how would you fix the loop invariant?
Debugging
Mid–senior
Add to study plan
Safe list mutation during iteration
A loop removes items from a list while iterating over it, and users report that some items survive the cleanup. Explain why elements get skipped and give two safe ways to write it.
Debugging
Entry–mid
Add to study plan
Moving zeros to array end
Given an array of integers, move every zero to the end while keeping the relative order of the non-zero elements. Do it in place with O(1) extra space.
Algorithms
Entry–mid
Add to study plan
Streaming average of k
Design a class that receives a stream of numbers and returns the average of the last k values after each insert. What do you store, and what's the cost per insert?
Data Structures
Entry–mid
Add to study plan
Detecting string rotation
Given two strings, determine whether one is a rotation of the other — for example, 'erbottlewat' is a rotation of 'waterbottle'. Aim for a solution that makes only one containment check.
Algorithms
Entry–mid
Add to study plan
Testing a URL slug function
A coding assistant drafted a function that slugifies arbitrary titles into URL-safe strings, and all the tests it wrote for itself pass. What properties and adversarial inputs would you test before trusting it in production?
Testing
Mid–senior
Add to study plan
Searching rotated sorted array
Write a function that takes a sorted array rotated at an unknown pivot and a target value, then returns the index of the target in O(log n) time. If the target doesn't exist, return -1.
Algorithms
Entry–mid
Add to study plan
Circular buffer with wraparound
Implement a circular buffer with fixed capacity that supports enqueue, dequeue, and isFull operations in constant time. Explain how you handle wraparound and discuss thread-safety considerations.
Data Structures
Entry–mid
Add to study plan
Cycle detection in directed graphs
Given a directed graph represented as an adjacency list, detect if there's a cycle. Optimize for graphs with millions of nodes and explain your space-time trade-offs.
Algorithms
Mid–senior
Add to study plan
Optimizing memoized Fibonacci
You're given a function that calculates Fibonacci numbers recursively with memoization, but profiling shows it's still slow for n > 10,000. Identify the bottleneck and propose two different optimizations.
Debugging
Mid–senior
Add to study plan
O(1) insert, delete, and random
Design a data structure that supports insert, delete, and getRandom in average O(1) time. All elements have equal probability of being returned by getRandom.
Data Structures
Mid–senior
Add to study plan
Merging K sorted linked lists
Implement a function that merges K sorted linked lists into one sorted list. Analyze the time complexity of your approach and explain when you'd choose an alternative algorithm.
Algorithms
Mid–senior
Add to study plan
Validating binary search trees
Write a function that takes a binary tree and returns true if it's a valid binary search tree. Consider edge cases including duplicate values, integer overflow, and the definition you're using for validity.
Data Structures
Entry–mid
Add to study plan
Testing financial transaction reconciliation
You have a distributed system that processes financial transactions. Write a test plan for a function that reconciles accounts across three data centers. What test cases matter most and why?
Testing
Senior–staff+
Add to study plan
Maximum subarray with one removal
Given an array of integers, find the maximum sum of any contiguous subarray. Then extend your solution to handle the case where you can remove at most one element from the chosen subarray.
Algorithms
Mid–senior
Add to study plan
Min-heap with decreaseKey operation
Implement a min-heap that supports standard operations plus a decreaseKey function in O(log n) time. Explain where this data structure is essential and why a balanced BST wouldn't suffice.
Data Structures
Mid–senior
Add to study plan
Autocomplete system with caching strategy
Design an autocomplete system that returns the top 3 most frequent search queries matching a prefix. Optimize for read-heavy workloads with millions of queries per second and explain your caching strategy.
System Reasoning
Senior–staff+
Add to study plan
Word frequency memory leak
You're reviewing code that uses a hash table to count word frequencies in a document, but it's running out of memory on production logs. Walk through your debugging process and propose fixes.
Debugging
Mid–senior
Add to study plan
String subsequence matching and optimization
Write a function that determines if one string is a subsequence of another. Then optimize it to handle a stream of queries against a single, fixed parent string.
Optimization
Mid–senior
Add to study plan
Thread-safe blocking queue implementation
Implement a thread-safe blocking queue with a maximum capacity. Support put, take, and tryTake with timeout. Discuss your choice of synchronization primitives and potential deadlock scenarios.
Data Structures
Senior–staff+
Add to study plan
Searching sorted matrix efficiently
Given a matrix where each row and column is sorted in ascending order, write a function to search for a target value in O(m + n) time. Explain why binary search on each row isn't optimal here.
Algorithms
Entry–mid
Add to study plan
URL shortener design and scaling
Design a URL shortener that generates unique short codes and redirects users. Handle collisions, discuss how you'd scale to a billion URLs, and explain your choice of character set for codes.
System Reasoning
Mid–senior
Add to study plan
Testing mathematical expression parser
Write unit tests for a function that parses and evaluates mathematical expressions with parentheses, addition, subtraction, multiplication, and division. What edge cases would you prioritize?
Testing
Mid–senior
Add to study plan
Longest palindromic substring approaches
Implement a function that finds the longest palindromic substring in a given string. Compare at least two approaches with different time-space trade-offs and explain when you'd use each.
Optimization
Mid–senior
Add to study plan
Deep-copying tree with random pointers
You're given a binary tree where each node has a random pointer that may point to any node in the tree or null. Write a function to deep-copy the tree, preserving all random pointers correctly.
Data Structures
Senior–staff+
Add to study plan
Batched logging with flush policies
Design a logging library that batches writes to disk to minimize I/O. Implement flush policies based on time, buffer size, and log level. Discuss how you'd test durability guarantees without actual disk access.
System Reasoning
Senior–staff+
Add to study plan
Finding common free time slots
Given a list of time intervals representing busy periods for N people, find all time slots where everyone is free for at least K minutes. Optimize for the common case where most intervals don't overlap.
Algorithms
Mid–senior
Add to study plan
Debugging and optimizing edit distance
Here's a function that computes edit distance between two strings using dynamic programming, but it's failing on strings longer than 10,000 characters. Debug it and propose both a memory optimization and a way to handle even larger inputs.
Debugging
Senior–staff+
Add to study plan
Consistent hashing with virtual nodes
Implement a consistent hashing ring for distributing cache keys across N servers. Support adding and removing servers with minimal key reassignment. Explain how virtual nodes improve balance.
Data Structures
Senior–staff+
Add to study plan
Three-sum zero triplets
Write a function that takes an array of integers and returns all unique triplets that sum to zero. Optimize to avoid duplicate triplets and analyze how your approach scales with input size.
Algorithms
Mid–senior
Add to study plan
Testing payment API idempotency
Design a test harness for a payment processing API that must validate idempotency, handle retries correctly, and maintain exactly-once semantics. What failure modes would you simulate and how?
Testing
Senior–staff+
Add to study plan