Java runtime 5ms - O(n) - beats 100%
\nclass Solution {\n    private static final long MOD = 1000000007;\n    \n    public int dieSimulator(int n, int[] rollMax) {\n        long[][] all = new long[
```\nclass Solution {\n    private static final long MOD = 1000000007;\n    \n    public int dieSimulator(int n, int[] rollMax) {\n        long[][] all = new long[6][15 + 1];\n        long[] countsBySide = new long[6];\n        long total = 0, newTotal;\n        int max;\n\n        for(int j = 0; j < all.length; j++) {\n            all[j][0 + 1] = 1;\n            countsBySide[j] = 1;\n            \n            total = 6;\n        }\n\n        for(int i = 1; i < n; i++) {\n            newTotal = total;\n            \n            for(int j = 0; j < all.length; j++) {\n                all[j][0] = (total - countsBySide[j]) % MOD;\n\n                max = rollMax[j];\n\n                newTotal = (newTotal - all[j][max] + all[j][0]);\n                \n                countsBySide[j] = (total - all[j][max]) % MOD;\n\n                for(int k = max; k >= 1; k--) {\n                    all[j][k] = all[j][k - 1];\n                }\n\n                // all[j][0] = 0;\n            }\n            \n            total = newTotal;\n        }\n        \n        return (int) (total % MOD);\n    }\n}\n```
[]