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