Data Structures & AlgorithmsVery hardICPC regional · Product Company SDE

Problem: Bob has the numbers 1 to 10 written on a board. He repeatedly erases the two largest numbers and writes their difference. After 9 operations one number remains. What is that final number?

  1. A. 2
  2. B. 1
  3. C. 0
  4. D. 3

Correct answer: B. 1

Use a max-heap to pick the two largest values each round, and write their absolute difference (which is the difference since the larger is taken first). Erasing the two smallest values gives a different final number.

More Coding Interview Problems questions

Exams that ask this topic