Here’s a progressive set of Python “whiteboard‐style” exercises—from easy warm-ups up through recursion, data structures and algorithm challenges—you’d typically see in a solid tech interview. For each problem I’ll give you:
- A brief description
- Key topics being tested
- Example inputs/outputs
- Hint or two on how to approach
Enjoy! 🚀
1. Easy Warm-Ups
| # | Title | Topics |
|---|
| 1 | Two-Sum | Hash table, arrays |
| 2 | Reverse Words in a String | String manipulation |
| 3 | Rotate Array by k Positions | Arrays, modulo arithmetic |
1.1 Two-Sum
Prompt
Given an array of ints nums and a target t, return indices (i, j) so that nums[i] + nums[j] == t.
Example
nums = [2,7,11,15], t = 9 → (0,1)
Hint
Use a dict to store value→index as you iterate, checking if t−num exists.
1.2 Reverse Words in a String
Prompt
Given "the sky is blue", return "blue is sky the".
Example
input: " hello world! "
output:"world! hello"
Hint
Split on spaces, filter out empty tokens, then .reverse() or slice.
1.3 Rotate Array by k Positions
Prompt
Rotate the array to the right by k steps, in-place if possible.
Example
nums = [1,2,3,4,5,6,7], k=3 → [5,6,7,1,2,3,4]
Hint
Reverse the whole array, then reverse the first k and the last n−k.
2. Intermediate: Data Structures & Recursion
| # | Title | Topics |
|---|
| 4 | Merge Two Sorted Linked Lists | Linked list manipulation |
| 5 | Validate Binary Search Tree (BST) | Trees, recursion |
| 6 | Combination Sum | Backtracking, recursion |
2.4 Merge Two Sorted Linked Lists
Prompt
Given heads l1 and l2 of two sorted linked lists, merge them into one sorted list.
Hint
Use a dummy head and tail pointer; iterate both lists.
2.5 Validate BST
Prompt
Given a binary tree, determine if it’s a valid BST (left < node < right).
Hint
Do an in-order traversal and check ascending order, or pass down (min, max) bounds.
2.6 Combination Sum
Prompt
Given candidates (no duplicates) and target, find all unique combinations where numbers sum to target. You may reuse elements.
Example
candidates = [2,3,6,7], target = 7
→ [[7], [2,2,3]]
Hint
Backtrack, keep a start-index to avoid duplicates, prune when sum exceeds target.
3. Advanced: Graphs, DP, System-Style Thinking
| # | Title | Topics |
|---|
| 7 | Word Ladder | BFS, graph modeling |
| 8 | LRU Cache | Design, hashing + doubly linked list |
| 9 | Serialize & Deserialize Binary Tree | Trees, recursion, string parsing |
| 10 | Longest Increasing Subsequence (LIS) | Dynamic programming, binary search |
3.7 Word Ladder
Prompt
Given beginWord, endWord, and wordList, return shortest transformation length (one letter change each step).
Hint
Construct a graph implicitly: for each word, replace each char with * wildcard, map to word list. Then BFS.
3.8 LRU Cache
Prompt
Design an LRUCache class with get(key) and put(key, value) in O(1).
Hint
Use a dict for fast lookup + a doubly linked list to track recency.
3.9 Serialize & Deserialize Binary Tree
Prompt
Implement serialize(root) → string and deserialize(data) → root.
Hint
Pre-order with null markers (e.g. 'X'), then use an iterator over tokens to rebuild.
3.10 Longest Increasing Subsequence (LIS)
Prompt
Given an int array, return length of LIS.
Hint
Two approaches:
- O(n²) DP:
dp[i]=1+max(dp[j]) for j<i and arr[j]<arr[i].
- O(n log n) patience sorting with a tails array + binary search.
4. Challenge & Follow-Ups
- Median of Two Sorted Arrays (Hard)
– Find median of two sorted arrays in O(log(m+n)).
- Word Search II (Hard)
– Given a grid and a list of words, find all words in the board. (Trie + DFS)
Tips for “Whiteboard” Prep
- State your approach first. Sketch data structures on the board.
- Discuss time/space complexity. Why is your choice O(n) vs O(n²)?
- Edge cases. Empty inputs, duplicates, very large k, negative numbers…
- Write clean code. Use helper functions (e.g.
_dfs(node)) and meaningful names.
- Test as you go. Walk through a small example once you’ve coded.
Good luck practicing! Let me know which problem you want to tackle first, or if you’d like a deeper hint/solution. 👍