Choosing a Technique
Which tool for which problem.
You've learned a whole toolbox. The hardest part of a new problem is knowing which tool to reach for. Luckily, problems leave clues in how they're worded.

- A whole toolbox
- Which tool?
- Problems leave clues
Clues and tools
Here's a cheat sheet. Sorted input suggests binary search, or two pointers. A continuous stretch suggests a sliding window. Have I seen this before, suggests a hash set or dictionary. Top K suggests a heap. Shortest steps suggests breadth first search. Every possible answer suggests backtracking. And count the ways, or the best total, suggests dynamic programming.
| The problem says | Try |
|---|---|
| sorted, find a pair | two pointers, binary search |
| substring, subarray, in a row | sliding window |
| seen before, duplicates, pairs | hash set or dict |
| top k, smallest, most urgent | heap |
| shortest steps, levels | BFS |
| all combinations | backtracking |
| number of ways, best total | dynamic programming |
When you are stuck
If no tool jumps out, start with a slow, simple solution, even O of N squared. Then ask, where is the repeated work? Can a dictionary remember it? Would sorting help? Can I reuse smaller answers? Improving a working solution is far easier than inventing a perfect one.
| key | value |
|---|---|
| Start simple | brute force first |
| Find repeats | what's recalculated? |
| Remember | dict, cache |
| Reuse | smaller answers |
Summary
Read the clues in the problem, and match them to a tool. If stuck, start simple and improve. Next, a new section. Interview practice.
Key takeaways- Read the clues
- Match a tool
- Brute force, then improve