Loading...
You are given an integer n. The numbers 1 through n are arranged in a circle in increasing order.
Starting from number 1, repeatedly skip the next remaining number, then remove the number right after it, counting only numbers that are still present. So the first number skipped is 1 and the first number removed is 2, the next skipped is 3 and the next removed is 4, and so on around the circle. Continue until every number has been removed.
Return an array containing the numbers in the order they were removed.
Input: n = 7
Output: [2, 4, 6, 1, 5, 3, 7]
Explanation:
Round the circle 1..7: skip 1, remove 2; skip 3, remove 4; skip 5, remove 6.
Back at the start: skip 7, remove 1; skip 3, remove 5.
Remaining [3, 7]: skip 7, remove 3; skip 7, remove 7.
Input: n = 2
Output: [2, 1]
Explanation:
Skip 1, remove 2; then skip 1 (alone in the circle), remove 1.
n ≤105Click "Run" to test with sample cases or "Submit" to run all tests.