Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 C

Problem: The elimination game: numbers 1 to 9 are written in a row. Repeatedly remove alternate numbers, starting from the left, then from the right (alternating), until one number remains. Which number is left?

  1. A. 8
  2. B. 4
  3. C. 9
  4. D. 6

Correct answer: D. 6

Left pass leaves 2, 4, 6, 8; right pass removes 8 and 4, leaving 2, 6; left pass removes 2, leaving 6. Always removing from the left gives 8, starting from the right gives 4, and keeping instead of removing the first element gives 9.

More Coding Interview Problems questions

Exams that ask this topic