Elimination Game
Medium · Math, Recursion
You have a list arr of all integers in the range [1, n] sorted in a strictly increasing order. Apply the following algorithm on arr:
Given the integer n, return the last number that remains in arr.
Example 1
Input: n = 9 Output: 6
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9] arr = [2, 4, 6, 8] arr = [2, 6] arr = [6]
Example 2
Input: n = 1 Output: 1
Constraints
- 1 <= n <= 109
Starter code (python)
class Solution(object):
def lastRemaining(self, n):
"""
:type n: int
:rtype: int
"""
Related problems
- Add Two Numbers (Medium)
- Reverse Integer (Medium)
- Palindrome Number (Easy)
Previous: Ransom Note · Next: Perfect Rectangle · All problems
Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.