download

Algorithms Interview Questions

Practice arrays, sliding windows, binary search, trees, graphs, heaps, and dynamic programming with free algorithms interview questions. Each exercise includes hints and a checked explanation.

Algorithms39 questionsFree · No sign-in

Practice questions

  1. Largest sum of exactly k numbers in a row, negatives included · sliding window · 10 min
  2. Binary search with duplicates: how do you find the first match? · binary search · 15 min
  3. Fewest links or least time: BFS or Dijkstra? · shortest paths · 15 min
  4. Most water between two lines: why is moving the shorter line safe? · two pointers · 15 min
  5. Longest run after k replacements: why can the max count stay stale? · sliding window · 20 min
  6. Count subarrays that sum to k when numbers can be negative · prefix sums · 15 min
  7. Your zero-rows-and-columns code wipes the whole matrix. Why? · matrices · 12 min
  8. For each day, how many days until a warmer one? · monotonic stack · 15 min
  9. How do you keep a running median as numbers arrive? · heaps · 20 min
  10. Meetings 9–10 and 10–11 fit one room. Why do you get two? · intervals · 15 min
  11. Ship all packages in D days: what exactly do you binary search? · binary search · 20 min
  12. Does this linked list loop? Answer with O(1) extra memory · linked lists · 15 min
  13. Can you take every course, and which ones stay blocked? · topological sort · 20 min
  14. Longest increasing subsequence: from O(n²) to O(n log n) · dynamic programming · 25 min
  15. Edit distance between two words: what does each table cell mean? · dynamic programming · 20 min
  16. Water spreads one cell a minute. When is every cell wet? · graph search · 20 min
  17. All distinct orders of [1, 1, 2]: how do you avoid repeats? · backtracking · 20 min
  18. 0/1 knapsack in one array: why loop capacity downwards? · dynamic programming · 15 min
  19. Why does greedy coin change fail, and what fixes it? · dynamic programming · 15 min
  20. Which of these list, set and deque operations are O(1)? · complexity · 10 min
  21. Build a queue from two stacks. Why is it O(1) amortized? · queues · 15 min
  22. Design a stack that returns its minimum in O(1) · stacks · 10 min
  23. Reverse a singly linked list in place without losing nodes · linked lists · 10 min
  24. Two keys share a bucket. How does a hash map cope? · hash tables · 12 min
  25. Why did your object vanish from a set after you changed it? · hash tables · 10 min
  26. Design an LRU cache with O(1) get and put · caching · 15 min
  27. Deep-copy a linked list whose nodes have a random pointer · linked lists · 15 min
  28. Is this tree a valid BST? Why checking children isn't enough · binary search trees · 15 min
  29. Delete a BST key whose node has two children · binary search trees · 20 min
  30. Preorder, inorder, postorder, level order: when do you use each? · trees · 10 min
  31. You insert sorted keys into a BST. Why does it get slow? · binary search trees · 10 min
  32. Find the kth largest number: heap or quickselect? · heaps · 15 min
  33. Delete a word from a trie without losing "car" or "cards" · tries · 20 min
  34. Edges arrive one by one. How many groups are there now? · union-find · 20 min
  35. Adjacency list or matrix: which one for this graph? · graphs · 10 min
  36. Substring search on repeating text: how does KMP skip ahead? · String matching · 15 min
  37. Maximum non-overlapping intervals: which greedy sort order works? · Greedy intervals · 12 min
  38. Dijkstra returns the wrong distance with a negative edge. Fix it · Shortest paths · 15 min
  39. Grid BFS with one wall break returns -1. Why? · State-space BFS · 15 min

How to practice

Predict the result or explain what you would change before opening the hints. Then compare your reasoning with the answer and try the follow-up question.

Open the interactive Algorithms deck →