Given a positive integer n, return the number of all possible attendance records with length n, which will be regarded as rewardable. The answer may be very large, return it after \$\mod 10^9 + 7\$.A student attendance record is a string that only contains the following three characters:'A' : Absent.'L' : Late.'P' : Present.A record is regarded as rewardable if it doesn't contain more than one 'A' (absent) or more than two continuous 'L' (late). Link to this question on leetcode is hereI was able to come up with a recursive approach but could not memoize it like in DP. I want to use the same approach but with memoization. Below is my submitted code.public class Solution {    public long count = 0;    public int checkRecord(int n) {        func(1,n,0,0);        return (int)count % (1000000007) ;    }    public void func(int pos , int n , int alreadyAbsent , int countOfLate)    {        if(pos > n)        {            count++;        }        else        {            func(pos + 1, n , alreadyAbsent,0);            if(countOfLate < 2)            {                func(pos + 1,n,alreadyAbsent,countOfLate + 1);            }            if(alreadyAbsent == 0)            {                func(pos + 1,n,1,0);            }        }    }}
Count all possible attendance records with length n, which will be regarded as rewardable
java;algorithm;programming challenge;recursion;combinatorics