DSA and coding interview practice

Original coding interview problems as two-minute exercises. Commit to an answer first, then check it and read the full explanation with runnable Python.

Prefer to just read? Every question has Show answer. Progress is saved on this device only, separately from the iOS, Android and Backend courses.

  1. PredictPick what the code returns, or tap the line with the bug.
  2. CheckSee whether you were right, and why every other option is wrong.
  3. Learn itRead the 30-second answer, then the solution, its cost and the follow-ups.

– interview-ready · 200 questions

– of 200 tried

Saved on this device. Interview-ready means you got it right on two different days. Guesses and hints count for less.

Daily 5

The same five questions for everyone today, with a grid to share. Needs JavaScript. Start with the first question.

Open today's Daily 5 page

Readiness by topic

Your progress is saved in this browser only. With JavaScript on, this shows each topic's readiness and lets you export your progress to a file or import it on another device.

Topics

Arrays, strings and hash maps

Hash sets and maps for seen-before checks, complements, counting keys and prefix sums; in-place array tricks; what lists and dicts really cost.

14 questions

Two pointers

Pointers from both ends of sorted data, read and write pointers for in-place edits, and merging sorted sequences, with the reasoning that makes them correct.

12 questions

Sliding window

Fixed and variable windows over arrays and strings, the amortised argument that makes them linear, and when a window is the wrong tool.

12 questions

Trees

Binary tree recursion, traversal orders, level-by-level walks, binary search tree rules and the questions built on them, all with one small Node class.

16 questions

Graphs

Grids and networks as graphs: BFS and DFS, multi-source BFS, topological order, union-find, Dijkstra and minimum spanning trees, with the costs you need to state.

22 questions

Complexity analysis

Big O in plain words, reading the cost of loops and recursion, amortised and space costs, what Python's built-in operations really cost, and which input sizes fit which algorithms.

14 questions

Stacks and queues

Stacks for matching and undo, queues for order of arrival, monotonic stacks for 'next bigger' questions, and how to build one from the other.

12 questions

Searching sorted data

Binary search on sorted lists, on rotated lists and grids, and on the answer itself, with the loop invariants that prevent off-by-one bugs.

12 questions

Linked lists

Chains of links: turning them around, fast and slow pointers, the placeholder head, and when a chain beats a Python list.

10 questions

Heaps and priority queues

Min-heaps by hand and with heapq: the k largest, merging sorted feeds, running medians and greedy choices that always take the smallest or biggest next.

10 questions

Backtracking

Choose, explore, undo: listing selections and orderings, searching grids and boards, and pruning the search so exponential work stays small in practice.

12 questions

Dynamic programming

Turning repeated recursion into tables: state, transition, base case and fill order, from one-row counts to two-string tables, with the memory tricks interviewers ask about.

18 questions

Greedy choices and intervals

Sorting intervals by start or end, sweeping through events, and greedy rules you can prove with an exchange argument.

12 questions

Strings and tries

Prefix trees for lookups and suggestions, expanding around centres, linear-time pattern search, and what Python strings cost.

10 questions

Bits and maths

XOR, masks and shifts, counting 1 bits, and the modular arithmetic that keeps big counts manageable.

6 questions

Interview craft

How to run a coding interview from the first question to the last test: clarifying, choosing a pattern, talking while you code, dry runs and testing.

8 questions

All questions

Arrays, strings and hash maps

  1. Spot the first repeated badge at the doorPredict
  2. Two gift prices that hit the budget exactlyFill the blank
  3. Group tile racks that hold the same lettersPredict
  4. Count sales stretches that add up to a targetPredict
  5. Longest run of consecutive ticket numbersPick the fix
  6. Find the value that fills more than half the listPredict
  7. Each shelf's product of all the other shelvesSpot the bug
  8. Shift a playlist k places to the right, in placeOrder the steps
  1. First order code that appears only oncePredict
  2. Find the balance point of a seesawFill the blank
  3. How a hash map keeps lookups fast on averagePick the fix
  4. Why appending to a list is amortized O(1)Predict
  5. What makes a good dictionary keyPredict
  6. Count or sort: choosing a frequency toolPredict

Two pointers

  1. Do two sorted prices add up to a target?Predict
  2. Push the empty parking slots to the endSpot the bug
  3. Does a banner read the same both ways?Predict
  4. Merge two sorted shelves into oneFill the blank
  5. Remove repeated readings from a sorted log in placePredict
  6. Count weight triples that stay under a limitPredict
  7. Squared deviations in sorted orderPick the fix
  8. Is a short route hidden inside a long one?Predict
  1. Sort a tray of three token colours in one passSpot the bug
  2. When do two pointers work, and why?Pick the fix
  3. Same-direction vs opposite-end pointersPredict
  4. In place or a new list: what the interviewer meansPredict

Sliding window

  1. Longest streak of days within a budgetPredict
  2. Longest stretch of a log with no letter seen twiceSpot the bug
  3. Best total over k consecutive daysFill the blank
  4. Shortest run of orders that reaches a goalPredict
  5. Where does a rearranged pattern appear in a text?Predict
  6. Longest single-colour run after repainting k tilesPick the fix
  7. Best single buy-then-sell on a price historyPredict
  8. Longest stretch with at most two kindsPredict
  1. Busiest hour in each k-hour spanFill the blank
  2. Fixed-size vs variable-size windowsPick the fix
  3. Why a window with a nested loop is still O(n)Predict
  4. When a sliding window does not workPredict

Trees

  1. How trees are written on these pagesPredict
  2. How deep is the deepest branch?Pick the fix
  3. Is this a valid binary search tree?Pick the fix
  4. List a tree's values row by rowFill the blank
  5. Are two trees identical?Predict
  6. Does a tree mirror itself?Pick the fix
  7. Swap every node's left and right childrenPredict
  8. Longest path between any two nodesPick the fix
  1. Is every node's left and right height within one?Predict
  2. What you see from the right of a treePick the fix
  3. The k-th smallest value in a search treeOrder the steps
  4. Closest shared ancestor in a search treePredict
  5. Does a root-to-leaf route add up to a target?Pick the fix
  6. Pre-order, in-order, post-order and level orderPredict
  7. Why search trees need to stay balancedPredict
  8. Recursion depth and when to walk a tree iterativelyPredict

Graphs

  1. Count the separate patches of land on a mapPredict
  2. Can every task finish, given its prerequisites?Pick the fix
  3. Minutes until every item on a shelf spoilsFill the blank
  4. How many separate groups does a network have?Predict
  5. Fewest hops between two stationsPick the fix
  6. Fastest delivery time to every depotPredict
  7. The earliest valid task orderPredict
  8. Seat guests at two tables with no feud at eitherPick the fix
  1. Which cable closes a loop?Predict
  2. Area of the biggest patch of landPredict
  3. Repaint the connected region of a picturePick the fix
  4. Fewest one-letter changes between two code wordsPredict
  5. Does a dependency graph contain a loop?Pick the fix
  6. Cheapest way to cable every office togetherOrder the steps
  7. Cells whose rain reaches both coastsPick the fix
  8. Fill in the water that does not touch the edgePredict
  9. Adjacency list, adjacency matrix or edge list?Predict
  10. BFS or DFS: which one to usePick the fix
  11. Mark visited when you push or when you pop?Predict
  12. Why Dijkstra fails with negative weightsPick the fix
  13. Union-find: how it works and when to reach for itPredict
  14. Grids are graphs: neighbours, bounds and costsPredict

Complexity analysis

  1. Big O in plain wordsPredict
  2. Reading the cost of loopsPredict
  3. Where O(log n) comes fromPredict
  4. Amortised cost: cheap on average, sometimes slowPredict
  5. Space complexity and the call stackPredict
  6. What common Python operations costPredict
  7. Which complexity fits which input sizePredict
  8. Best, average and worst casePredict
  1. Working out the cost of recursionPredict
  2. How fast can sorting be?Predict
  3. The cost of building stringsPredict
  4. The cost table for common data structuresPick the fix
  5. Answer many range-total questions quicklyFill the blank
  6. Raise a number to a huge power, modulo mPredict

Stacks and queues

  1. Do the brackets in a line balance?Predict
  2. How many days until a warmer day?Pick the fix
  3. A stack that also reports its minimumPredict
  4. Evaluate an expression written in postfix orderPredict
  5. Apply the backspaces in typed textPredict
  6. Build a queue out of two stacksPredict
  7. Tidy a file path with . and .. partsPredict
  8. Largest poster that fits under a skylinePredict
  1. How many requests arrived in the recent window?Fill the blank
  2. Stack or queue: LIFO and FIFOPredict
  3. The monotonic stack patternPredict
  4. Recursion is a stack: converting to an explicit onePredict

Searching sorted data

  1. Where would a new price go in a sorted list?Predict
  2. Slowest reading pace that still finishes on timePredict
  3. Smallest value in a rotated sorted listPick the fix
  4. Find a value in a rotated sorted listPredict
  5. First and last position of a value in a sorted listFill the blank
  6. Whole-number square root without math.sqrtPredict
  7. Smallest truck that delivers every parcel in d daysPredict
  8. Highest point of a climb-then-descent routePick the fix
  1. Find a value in a grid sorted row after rowPredict
  2. Binary search without off-by-one bugsPredict
  3. Binary search on the answerPick the fix
  4. Using bisect and sorted lists in practicePredict

Linked lists

  1. How linked-list questions give you the chainPredict
  2. Turn a chain of links aroundOrder the steps
  3. Does the chain loop back on itself?Pick the fix
  4. Drop the k-th link from the endPredict
  5. Weave two sorted chains into oneFill the blank
  6. Fold a chain: first, last, second, second-lastPredict
  7. Sum two numbers stored digit by digitPredict
  8. Does a chain read the same backwards?Pick the fix
  9. The placeholder head trickSpot the bug
  10. When a chain beats a Python listPick the fix

Heaps and priority queues

  1. Push values into a min-heap by handPredict
  2. The k-th biggest readingFill the blank
  3. Merge many sorted feeds into onePredict
  4. The k depots nearest the warehousePredict
  5. Fewest time slots when each job type needs a cooldownPredict
  6. Median after each new readingPredict
  7. Smash the two heaviest rocks until one is leftPredict
  8. Cheapest way to join ropes into onePredict
  9. How a binary heap worksPredict
  10. Heap, sort or quickselect?Pick the fix

Backtracking

  1. Count the picks that hit an exact totalPredict
  2. Every order of a playlistPredict
  3. Every selection from a set of toppingsPredict
  4. Every team of k from n playersFill the blank
  5. Every balanced string of n bracket pairsPredict
  6. Trace a word through a letter gridPick the fix
  7. Cut a word into pieces that each read the same backwardsPredict
  8. Count the ways to place queens that cannot attackPredict
  1. Every distinct order when songs repeatPredict
  2. The backtracking template: choose, explore, undoOrder the steps
  3. Pruning: making exponential searches fast enoughPick the fix
  4. How big is the search space?Predict

Dynamic programming

  1. Ways to cross n stepping stones, one or two at a timePredict
  2. Fewest coins to make an amountPredict
  3. Fewest edits to turn one word into anotherPredict
  4. Best haul without opening two neighbouring lockersPredict
  5. Best haul when the lockers form a ringPick the fix
  6. Ways to read a digit string as letters (1 = A … 26 = Z)Predict
  7. Can a string be split into dictionary words?Predict
  8. Longest rising sequence of picks from a listPredict
  1. Longest shared subsequence of two stringsPredict
  2. Routes across a grid with blocked cellsPredict
  3. Cheapest route from top-left to bottom-rightPredict
  4. Split items into two piles of equal weightPredict
  5. Number of ways to pay an amount with unlimited coinsPredict
  6. Largest product of a contiguous runPredict
  7. Dynamic programming in four stepsOrder the steps
  8. Top-down caching or bottom-up tables?Predict
  9. Saving memory with rolling rowsPredict
  10. How to tell a problem needs DPPick the fix

Greedy choices and intervals

  1. Combine overlapping bookings into blocksPredict
  2. Fewest bookings to cancel so none clashPick the fix
  3. How many rooms do the bookings need at once?Predict
  4. Add a booking to a sorted list of separate blocksPredict
  5. Can you hop to the last tile?Predict
  6. Fewest hops to the last tilePredict
  7. Where to start a delivery loop so the van never runs dryPredict
  8. Cut a string into the most chunks so no letter crosses a cutPredict
  1. Largest total of a contiguous runPredict
  2. When does a greedy choice work?Pick the fix
  3. Sort intervals by start or by end?Pick the fix
  4. Sweep-line thinkingPredict

Strings and tries

  1. How many words start with a given prefix?Predict
  2. Longest stretch that reads the same backwardsPredict
  3. First place a pattern appears in a textPredict
  4. Top three suggestions as you typePredict
  5. Look up words where '.' stands for any letterPredict
  6. Count the stretches that read the same backwardsPredict
  7. Longest start shared by every wordPredict
  8. What Python string operations costPredict
  9. Trie or hash set?Pick the fix
  10. Rolling hashes for pattern searchPredict

Bits and maths

  1. The one value without a partnerPredict
  2. Count the 1 bits in a numberPredict
  3. 1-bit counts for every number from 0 to nPredict
  4. Which ticket from 0 to n is absent?Predict
  5. Bit tricks worth knowingPredict
  6. Working modulo 10⁹ + 7Predict

Interview craft

  1. Spotting the pattern from the questionPick the fix
  2. The first five minutes of a coding interviewOrder the steps
  3. Brute force first, then improvePredict
  4. Count position pairs whose values differ by exactly kPredict
  5. Talking while you codePick the fix
  6. Dry run: the first day an account is overdrawnPredict
  7. Testing your own code in an interviewPredict
  8. What to do when you are stuckOrder the steps

Sources: Topic outline informed by the Tech Interview Handbook by Yangshun Tay and the NeetCode 150 pattern grouping by neetcode-gh, both MIT licensed. Every problem, solution and explanation is written by Best Latest Apps. Credits and license