Tap here to switch tabs
Problem
Submissions

Problem: Elimination Game

med
30 min
Try to solve the Elimination Game problem.

Statement

You have a list arr consisting of all integers in the range [11, n] sorted in strictly increasing order.

Apply the following algorithm on arr:

  • Moving from left to right, remove the first number and every alternate number until reaching the end of the list.

  • Next, moving from right to left, remove the rightmost remaining number and every alternate number moving toward the front.

  • Continue repeating these steps, alternating directions between left to right and right to left, until only one number remains.

Given the integer n, return the last remaining number in arr.

Constraints:

  • 1≤1 \leq n ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Elimination Game

med
30 min
Try to solve the Elimination Game problem.

Statement

You have a list arr consisting of all integers in the range [11, n] sorted in strictly increasing order.

Apply the following algorithm on arr:

  • Moving from left to right, remove the first number and every alternate number until reaching the end of the list.

  • Next, moving from right to left, remove the rightmost remaining number and every alternate number moving toward the front.

  • Continue repeating these steps, alternating directions between left to right and right to left, until only one number remains.

Given the integer n, return the last remaining number in arr.

Constraints:

  • 1≤1 \leq n ≤109\leq 10^9