Two Sum is the first problem almost everyone learns, and most people stop preparing for it the moment they can write the hash map solution in their sleep. That is a mistake, because nobody who has actually interviewed candidates asks Two Sum to see if you know the hash map trick. They ask it because it is a five minute warm up that opens the door to four follow ups, and the follow ups are where you are actually being scored.
The four follow ups
1. "What if the array is sorted?"
This is checking whether you default to the same tool every time or whether you actually look at the input before reaching for a hash map. A sorted array means two pointers gets you O(1) space instead of O(n), and an interviewer wants to see you notice that on your own, not after a hint.
2. "What if there are duplicate values?"
This is checking whether your solution quietly breaks on an edge case you did not think about out loud. Walk through what happens to your hash map when the same value appears twice before you get asked, not after.
3. "What if I asked you to return all pairs, not just one?"
This changes the shape of the problem. Your early return solution now has to become a collection step, and the interviewer is watching whether you can adapt an existing solution instead of throwing it out and starting over.
4. "Can you do it without extra space?"
For an unsorted array this is often impossible in less than O(n log n) time, and the correct answer is to say so and explain the tradeoff, not to awkwardly force a bad solution. Interviewers use this one specifically to see if you will push back on a constraint that does not make sense, which matters more in a real job than getting every question right.
Why this matters more than grinding more problems
None of these four follow ups require knowing a new algorithm. They require having sat across from someone who asks them, often enough that reacting to a follow up feels normal instead of stressful. Reading the follow up in a blog post and living through it live are different skills, and only one of them is what actually gets tested.
That is the gap that solo practice cannot close, and it is why I ended up building Practick, a free peer to peer mock interview platform. You get matched with another engineer, one hour you are the candidate and one hour you are the interviewer, so you spend time on both sides of exactly this kind of exchange instead of only ever answering.
Top comments (0)