Easy C++ O(N) solution.
Since there are only 6 dies, the time complexity is O(6n) since 6n states are calculated.\n Each state is combination of remaining no. of elements to add to the
* Since there are only 6 dies, the time complexity is O(6*n) since 6n states are calculated.\n* Each state is combination of remaining no. of elements to add to the sequence and the previous die used (so that we can avoid using it).\n* Try all possible consecutive duplicates of the same die. E.g. If ```rollMax[2] = 3```, try ```2, 22, 222.``` \n\n```\nclass Solution {\npublic:\n    vector<int> maxConsecutiveRoll;\n    vector<vector<int>> dp;\n    const int M = 1e9 + 7;\n    \n    int f(int n, int prevState){\n        if(n == 0){\n            return 1;\n        }\n        \n        if(n < 0){\n            return 0;\n        }\n        \n        if (dp[n][prevState] == -1){\n            int res = 0;\n\n            for(int i=1; i<=6; ++i){\n                if(i != prevState)\n                {\n                    for(int cnt=1; cnt<=maxConsecutiveRoll[i-1]; ++cnt)\n                        res = (res + f(n-cnt, i)) % M;\n                }\n            }\n            dp[n][prevState] = res;\n        }\n        return dp[n][prevState];\n    }\n    \n    int dieSimulator(int n, vector<int>& rollMax) {\n        maxConsecutiveRoll = rollMax;\n        dp.resize(n+1, vector<int>(7,-1));\n        return f(n, 0);\n    }\n};\n```
[]