Short, easy to understand Python recursive memoized solution
python\nfrom functools import lru_cache\nclass Solution:\n    def dieSimulator(self, n: int, rollMax: List[int]) -> int:\n        \n        @lru_cache(None)\n  
```python\nfrom functools import lru_cache\nclass Solution:\n    def dieSimulator(self, n: int, rollMax: List[int]) -> int:\n        \n        @lru_cache(None)\n        # args: die value we just rolled, number of consecutive rolls it came up, number of rolls left\n\t\t# returns # of possiblities given current state\n        def roll(val, cons, left):\n            if left == 0: return 1\n            \n            # number of possibilities aside from rolling `val` again. In the recursive call to `roll`,\n\t\t\t# `cons` is passed 1 because this is the first consecutive roll of this value\n            ans = sum([roll(nval, 1, left-1) for nval in range(6) if nval != val])\n            \n            # can roll `val` again only if consecutive rolls is less than max\n            if cons < rollMax[val]:\n                ans += roll(val, cons+1, left-1)\n                \n            return ans\n        \n\t\t# initial die value doesn\'t matter here since `cons`=0\n        return roll(0,0,n) % (10**9 + 7)\n```\n\n
[]