Last Remaining Number

Recursion

Given the integer n, you have a list of all integers in the range [1, n] sorted in a strictly increasing order. Performing the following steps:

Write a recursive function to solve this problem. The input contains 1 positive integer n with 1 <= n <= 109

Important Info:

Example 1:

Input: 4
Output: 2

Explanation: (bold indicate that the number is removed at that step)
arr = [1, 2, 3, 4]
arr = [2, 4]
arr = [2]

Example 2:

Input: 9
Output: 6

Explanation: (bold indicate that the number is removed at that step)
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
arr = [2, 4, 6, 8]
arr = [2, 6]
arr = [6]