You have a list arr consisting of all integers in the range [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:
n
You have a list arr consisting of all integers in the range [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:
n