xxxxxxxxxx
class Solution
{
//Function to count number of ways to reach the nth stair.
int mod = 1000000007;
int countWays(int n)
{
int[] dp = new int[n];
Arrays.fill(dp, -1);
return helper(n, 0, dp);
}
int helper(int n, int current, int[] dp) {
if (current > n)
return 0;
if (current == n)
return 1;
if (dp[current] != -1)
return dp[current];
return dp[current] = (helper(n, current + 1, dp) + helper(n, current + 2, dp))%mod;
}
}