🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.x itself
  2. B.target − x
  3. C.target + x
  4. 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 →