← Arrays & Hashing Quiz: all 8 questions
Arrays & Hashing Quiz · Question 2 of 8
In the hash-map solution for Two Sum, what do we look up for each number x?
In the hash-map solution for Two Sum, what do we look up for each number x?
- A.x itself
- B.target − x
- C.target + x
- D.x × 2
Answer & explanation
Correct answer: target − x
We need a partner p with x + p = target, so p = target − x. If it was seen earlier, we have the pair.
Can you get the rest right without peeking?
Take the timed Arrays & Hashing Quiz quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →