[Python] Backtracking with memoization
\nclass Solution:\n    def earliestAndLatest(self, n: int, firstPlayer: int, secondPlayer: int) -> List[int]:\n        \n        dp = {}\n\n        def getComb(
```\nclass Solution:\n    def earliestAndLatest(self, n: int, firstPlayer: int, secondPlayer: int) -> List[int]:\n        \n        dp = {}\n\n        def getComb(res, i, n):\n            if i==n:\n                return []\n            curr = res[i]\n            others = getComb(res, i+1, n)\n            total = []\n            for o in others:\n                for c in curr:\n                    total.append([c]+o)\n            return total\n        \n        def helper(state):\n            mask = tuple(state)\n            if mask in dp:\n                return dp[mask]\n            if len(state)==2:\n                dp[mask] = (1,1)\n                return (1, 1)\n            \n            res = []\n            while len(state)>1:\n                a = state.pop(0)\n                b = state.pop(-1)\n                if (a==firstPlayer and b==secondPlayer) or (b==firstPlayer and a==secondPlayer):\n                    dp[mask] = (1, 1)\n                    return (1, 1)\n                elif a==firstPlayer or a==secondPlayer:\n                    res.append((a, ))\n                elif b==firstPlayer or b==secondPlayer:\n                    res.append((b, ))\n                else:\n                    res.append((a, b))\n            if len(state)>0:\n                res.append((state[0], ))\n            comb = getComb(res, 0, len(res))\n            m, M = float("inf"), -float("inf")\n            for c in comb:\n                a, b = helper(c.sort())\n                m = min(a, m)\n                M = max(b, M)\n            dp[mask] = (1+m, 1+M)\n            return (dp[mask])\n        \n        arrang = []\n        for i in range(n):\n            arrang.append(i+1)\n        a, b = helper(arrang)\n        return [a, b]\n```
[]