📊WAS ASKED IN 3 INTERVIEW || SUPER EASY SOLUTION WITH DEFINITION OF THE STEPS || UPVOTE
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    private int dp[][][] = new int[5000][7][16];
    private int m;
    private int mod = (int)1e9+7;
    public int dieSimulator(int n, int[] rollMax) {
        m = n;
        return dfs(0,0,0,rollMax);
    }
    private int dfs(int i,int last, int curLen,int []rollMax)
    {
        if(i==m)return 1;
        int result = last>0?dp[i][last][curLen]:0;//this is cache
        if(result>0)return result;
        int res = 0;
        for(int die =1;die<=6;die++)
        {
            if(die==last&&curLen==rollMax[die-1])continue;//if the die was same as previous and the repetition of die exceeds rollMax;
            int tempLen = (die==last)?curLen+1:1;// if the previous was the same as the new die
            res+=dfs(i+1,die,tempLen,rollMax);// process for the next i
            res%=mod;//mod it
        }
        if(last>0)// if die was valid for process ie was between 1-6 store for cache
        {
            dp[i][last][curLen]=res;
        }
        return res;// solution ended;
    }
}
```
['Array', 'Dynamic Programming', 'Backtracking', 'Memoization', 'Matrix', 'Java']