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 trackingWorked choice
Problem: find if an array has any duplicate value.
Slow thought: compare every pair. That takes O(n²). Better thought: keep seen values in a set. Each membership check is usually O(1), so total time is O(n), with O(n) extra space.
def has_duplicate(nums):
seen = set()
for x in nums:
if x in seen:
return True
seen.add(x)
return False
def test_has_duplicate():
assert has_duplicate([1, 2, 3, 2]) is True
assert has_duplicate([1, 2, 3, 4]) is False
assert has_duplicate([]) is FalseCommon mistake
Do not say only “hash set is faster”. Say what became faster and what you paid for it.
A good interview answer is: “I use a set because membership checks drop from O(n) per check to usually O(1). Total time becomes O(n). Space becomes O(n).”
Use AI carefully
You can ask ChatGPT, Gemini, or Claude: “For this problem, list the repeated operations and suggest data structures with time and space costs.”
Check the answer yourself. AI often gives the final structure without saying the trade-off, or it may ignore duplicates, order, or worst-case cost.
Do this now
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