Python heap 🔥🔥
DP TLE\npython3 []\nclass Solution:\n    def maxScore(self, grid: List[List[int]]) -> int:\n        memo = {}\n        grid = [[i for i in range(1,11)] for j in
# DP TLE\n```python3 []\nclass Solution:\n    def maxScore(self, grid: List[List[int]]) -> int:\n        memo = {}\n        grid = [[i for i in range(1,11)] for j in range(10)]\n        grid = [sorted(list(set(grid[i])),reverse=True) for i in range(len(grid))]\n        def solve(curr,taken):\n            strpath = str(curr) + \',\' + str(taken)\n            if curr>=len(grid):\n                return 0\n            if strpath in memo:\n                return memo[strpath]\n            \n            memo[strpath] = 0\n            c = 0\n            for i in range(len(grid[0])-1,-1,-1):\n                if grid[curr][i] not in taken:\n                    memo[strpath] = max(memo[strpath],grid[curr][i]+solve(curr+1,list(taken)+[grid[curr][i]]))\n                    c += 1\n                if c>=len(grid)-curr:\n                    break\n            memo[strpath] = max(memo[strpath],solve(curr+1,list(taken)))\n            return memo[strpath]\n        return solve(0,[])\n```\n\n# Heap Accepted\n```python3 []\nclass Solution:\n    def maxScore(self, grid: List[List[int]]) -> int:\n        grid = [sorted(list(set(grid[i])),reverse=True) for i in range(len(grid))]\n        heap = [(0,list(grid))]\n        ans = 0\n        while heap:\n            curr,rems = heapq.heappop(heap)\n            if len(rems) == 0:\n                ans = max(ans,-curr)\n                continue\n            \n            rem = list([list(rems[i]) for i in range(len(rems))])\n            pos = []\n            maxa = 0\n            for j in range(len(rem)):\n                if len(rem[j])==0:\n                    continue\n                if rem[j][0] > maxa:\n                    pos = [j]\n                    maxa = rem[j][0]\n                elif rem[j][0] == maxa:\n                    pos.append(j)\n            for j in range(len(rem)):\n                for k in range(rem[j].count(maxa)):\n                    rem[j].remove(maxa)\n            for i in pos:\n                t = list([list(rem[j]) for j in range(len(rem))])\n                t.pop(i)\n                ans = max(ans,-(curr-maxa))\n                heapq.heappush(heap,(curr-maxa,list(t)))\n        return ans\n\n\n\n```
['Heap (Priority Queue)', 'Python3']