Say why, not just what
In interviews, picking the right data structure is only half the answer. You must explain why it fits the operations in the problem.
Use this pattern: operation needed, data structure chosen, cost, trade-off, edge case.
What interviewers listen for
They want to see that you can reason, not recite. If you choose a hash map, say it gives average O(1) lookup and update, but uses extra space.
If you choose a heap, say it helps when you repeatedly need the min or max item, not when you need sorted full output once.
Use a simple script
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
Repo note example
Add notes like this beside your solution files. Keep them short enough that someone can read them before opening the code.
Problem: First non-repeating character in a string
Choice:
Use a hash map to count characters, then scan the string again.
Why:
We need fast frequency lookup for each character.
A hash map gives average O(1) update and lookup.
Cost:
Time: O(n), because we scan the string twice.
Space: O(k), where k is the number of distinct characters.
Trade-off:
An array of size 26 works for lowercase English letters.
A hash map is safer if input can include uppercase, digits, or symbols.
Edge case:
If no non-repeating character exists, return -1.Compare one rejected choice
A strong answer includes one thing you did not choose. This shows judgement.
Example: “I did not sort because sorting is O(n log n), and the original order matters.”
Do not overclaim
Do not say hash maps are always O(1) without context. Say average O(1). Interviewers notice this.
Do not say linked lists are faster than arrays in general. Say linked lists make insert/delete cheap when you already have the node, but random access is O(n).
Spoken answer template
Practise saying this in 30 to 45 seconds. It works for most college internship interviews.
I need to find pairs that sum to target.
The repeated operation is checking whether target - current exists.
I will use a hash set because lookup is average O(1).
I scan the array once, check the complement, then add the current number.
Time is O(n). Space is O(n) in the worst case.
I am not using two pointers because the array is not sorted.
If sorting were allowed, two pointers would use less extra space but change the cost to O(n log n).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