#3782

Last Remaining Integer After Alternating Deletion Operations

candidate master · 1475 · lc hard +32 · premium · 48.6% accepted · 38 likes · top 35%

Description

Given an integer n, write the integers 1 through n in sequence and alternately apply two operations starting with operation 1 — operation 1 removes every other element from the left, operation 2 removes every other element from the right — continuing until one integer remains, then return it.

Code

1
2
3