100% runtime and memory
Runtime\nDetails\n419ms\nBeats 100.00%of users with JavaScript\nMemory\nDetails\n97.21MB\nBeats 100.00%of users with JavaScript\n\n# Code\n\n/**\n * @param {num
Runtime\nDetails\n419ms\nBeats 100.00%of users with JavaScript\nMemory\nDetails\n97.21MB\nBeats 100.00%of users with JavaScript\n\n# Code\n```\n/**\n * @param {number} n\n * @param {number[]} rollMax\n * @return {number}\n */\nvar dieSimulator = function(n, rollMax) {\n    let dp = {}\n    let help = (prev, rolls, rollsLeft) => {\n        if(rolls == n) return 1;\n        if(dp[rolls] == undefined) dp[rolls] = {}\n        if(dp[rolls][rollsLeft] == undefined) dp[rolls][rollsLeft] = {}\n        if(dp[rolls][rollsLeft][prev] != undefined) return dp[rolls][rollsLeft][prev]\n        let sum = 0;\n        for(let i = 0; i < rollMax.length; i++) {\n            if(rollsLeft === 0 && prev===i) continue\n            if(prev===i) sum += help(i, rolls+1, rollsLeft-1)\n            else sum += help(i, rolls+1, rollMax[i]-1)\n        }\n        \n        dp[rolls][rollsLeft][prev] = sum % ((10**9) + 7)\n        return dp[rolls][rollsLeft][prev]\n    }\n    return help(null, 0, Infinity)\n}\n```
['JavaScript']