[Python3] bit-mask dp
\n\nclass Solution:\n    def earliestAndLatest(self, n: int, firstPlayer: int, secondPlayer: int) -> List[int]:\n        firstPlayer, secondPlayer = firstPlayer
\n```\nclass Solution:\n    def earliestAndLatest(self, n: int, firstPlayer: int, secondPlayer: int) -> List[int]:\n        firstPlayer, secondPlayer = firstPlayer-1, secondPlayer-1 # 0-indexed\n        \n        @cache\n        def fn(k, mask): \n            """Return earliest and latest rounds."""\n            can = deque()\n            for i in range(n): \n                if mask & (1 << i): can.append(i)\n                    \n            cand = [] # eliminated player\n            while len(can) > 1: \n                p1, p2 = can.popleft(), can.pop()\n                if p1 == firstPlayer and p2 == secondPlayer or p1 == secondPlayer and p2 == firstPlayer: return [k, k] # game of interest \n                if p1 in (firstPlayer, secondPlayer): cand.append([p2]) # p2 eliminated \n                elif p2 in (firstPlayer, secondPlayer): cand.append([p1]) # p1 eliminated \n                else: cand.append([p1, p2]) # both could be elimited \n            \n            minn, maxx = inf, -inf\n            for x in product(*cand): \n                mask0 = mask\n                for i in x: mask0 ^= 1 << i\n                mn, mx = fn(k+1, mask0)\n                minn = min(minn, mn)\n                maxx = max(maxx, mx)\n            return minn, maxx\n        \n        return fn(1, (1<<n)-1)\n```
['Python3']