Tap here to switch tabs
Problem
Submissions

Problem: Last Remaining Integer After Alternating Deletions

Try to solve the Last Remaining Integer After Alternating Deletion Operations problem.

Statement

Given an integer n, you start with a list of integers from 11 to n sorted in ascending order from left to right.

You repeatedly apply the following elimination operations until only one integer remains:

  • Starting from the left, remove every second integer beginning with the second element from the left.

  • Starting from the right, remove every second integer beginning with the second element from the right.

  • Keep alternating between left to right and right to left passes until a single number is left.

Return the last remaining integer.

Constraints:

  • 1≤1 \leq n ≤1015\leq 10^{15}

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Last Remaining Integer After Alternating Deletions

Try to solve the Last Remaining Integer After Alternating Deletion Operations problem.

Statement

Given an integer n, you start with a list of integers from 11 to n sorted in ascending order from left to right.

You repeatedly apply the following elimination operations until only one integer remains:

  • Starting from the left, remove every second integer beginning with the second element from the left.

  • Starting from the right, remove every second integer beginning with the second element from the right.

  • Keep alternating between left to right and right to left passes until a single number is left.

Return the last remaining integer.

Constraints:

  • 1≤1 \leq n ≤1015\leq 10^{15}