Leetcode 390 Solution
This article provides solution to leetcode question 390 (elimination-game)
Access this page by simply typing in "lcs 390" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/elimination-game
Solution
class Solution:
def lastRemaining(self, n: int) -> int:
def last(n, left_to_right):
if n == 1:
return 1
if left_to_right:
return 2 * last(n // 2, False)
else:
return 2 * last(n // 2, True) - (n + 1) % 2
return last(n, True)