1. Pick by cost first
5 min
One rule
Pick by cost first. Not by what looks familiar or what you used in the last LeetCode problem.
For interviews, your first job is to match the operations in the problem to the cheapest data structure that supports them.
Cost means operations
A data structure is useful because it makes some operations cheap and others costly. Arrays are good when you need index access. Hash maps are good when you need fast lookup by key. Queues are good when you process items in arrival order.
Before you code, list the operations the problem needs. Common ones are lookup, insert, delete, update, get min or max, and traverse all items.
Ask these first
Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.
0 of 5 done
Small cost table
Add a note like this in your repo. It is simple enough to revise before interviews.
Do not memorise blindly. Use it to explain trade-offs.
Data structure | Fast at | Usually costs
Array/List | index access, append | lookup by value is O(n)
Hash map | lookup by key, count, last seen | extra space O(n)
Hash set | membership check, unique values | extra space O(n)
Stack | last-in-first-out problems | only top is easy
Queue | first-in-first-out problems | only front/back are easy
Heap | repeated min/max | not full sorted order
Tree/BST | ordered structure | balance matters
Graph | relationships and paths | traversal needs visited tracking