n are written in increasing order. They are swept in passes until only one number is left.
- The first pass goes left to right: it crosses out the first number and then every other number after it (the third, the fifth, and so on) to the end of the row.
- The second pass goes right to left: it crosses out the rightmost number and then every other number while moving left.
- After that the directions keep alternating.
Return the number that remains at the end.n=10 → 8
[1..10] → sweeping left to right removes 1, 3, 5, 7, 9: [2, 4, 6, 8, 10] → sweeping right to left removes 10, 6, 2: [4, 8] → sweeping left to right removes 4: [8].
n=6 → 4
[1..6] → [2, 4, 6] → sweeping right to left removes 6 and 2: [4].
n=1 → 1
n ≤ 10⁹n=10
8
Run checks the first 3 tests in your browser. Submit checks all 80 tests on the server, hidden ones included.