Data Structures & AlgorithmsHardFlipkart/Uber OA · placement

An array of size 9 holds the numbers 1..9, except that one number is missing and one number appears twice: [6, 5, 1, 3, 4, 7, 2, 8, 2]. Using the sum and the sum of squares (or XOR tricks), what are the repeated and the missing numbers?

  1. A. repeated 9, missing 2
  2. B. repeated 2, missing 9
  3. C. repeated 2, missing 1
  4. D. repeated 2, missing 10

Correct answer: B. repeated 2, missing 9

Σ expected − Σ actual = missing − repeated = 7, and Σ squares gives missing² − repeated² = 77, so missing + repeated = 11. Solving: repeated 2, missing 9.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic