01 · Why it’s true
Each data structure makes some operations cheap by organizing data in a particular way, which makes other operations more expensive. A hash map finds a key in constant time on average but keeps no order; a heap always gives you the smallest (or largest) item quickly but can’t search; a sorted structure supports ranges but costs more per insert.
So the right choice comes from the operations you need most. Name the operations first, then pick the structure that makes them cheap.
02 · Picture it
03 · In the interview
- Practical coding rounds: counting, top-K, sliding windows, and dedupe.
- Explaining why you chose a structure, not just using one.
- Talking through memory use for large inputs.
04 · Practice question
“From a stream of request logs, report the 10 slowest endpoints by average latency. Which data structures do you use?”
A strong answer covers
- A hash map from endpoint to running (total latency, count) — one O(1) update per line.
- At the end, compute averages and use a min-heap of size 10 to keep the top 10: O(m log 10) for m endpoints.
- Or simply sort the endpoints if m is small; say so.
- Mention edge cases: endpoints with very few requests, and parameters in paths that should be normalized (
/users/123→/users/:id).