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?
- A. 8
- B. 4
- C. 9
- 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
- Problem: The 3-bit Gray code sequence is 000, 001, 011, 010, 110, 111, 101, 100 for indices 0 to 7. What is the decimal value of the…
- Problem: How many subsets (including the empty set) of [1, 2, 3, 4, 5] have bitwise XOR equal to 0?
- Problem: How many integers from 1 to 100 are divisible by exactly one of 2 and 3?
- Problem: What is the last non-zero decimal digit of 10! (3628800)?
- Problem: Five people (including Alice and Bob) stand in a row. In how many arrangements do Alice and Bob stand next to each other?
- Problem: The array [3, 1, 2] undergoes one pass of bubble sort (compare each adjacent pair from left to right and swap if out of order)…