Python | Intuitive | Recursion + Memo | Explanation
At some ith roll, we care about what i - 1 roll was and how many times it occurred consecutively. We don\'t want to cross each roll limit.\n So our state space 
* At some ith roll, we care about what i - 1 roll was and how many times it occurred consecutively. We don\'t want to cross each roll limit.\n* So our state space includes (idx, prevNum, prevNumFreq) where idx is roll number, prevNum is the number which came up in (i - 1)th roll and prevNumFreq is the frequency of consecutive rolls of (i - 1)th number.\n* Since this is top down, the base case would be when we reach nth roll (0 - indexed) that means we succesfully created a valid sequence of size n so return 1.\n* Rest is implementation detail.\n```\nclass Solution:\n    def dieSimulator(self, n: int, rollMax: List[int]) -> int:\n        MOD = 10 ** 9 + 7\n        \n        @lru_cache(None)\n        def func(idx, prevNum, prevNumFreq):\n            if idx == n:\n                return 1\n            \n            ans = 0\n            for i in range(1, 7):\n                if i == prevNum:\n                    if prevNumFreq < rollMax[i - 1]:\n                        ans += func(idx + 1, i, prevNumFreq + 1)\n                        \n                else:\n                    ans += func(idx + 1, i, 1)\n            \n            return ans % MOD\n        \n        return func(0, 0, 0)
['Recursion', 'Python', 'Python3']