You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class Solution
{
public:
//Function to count the number of ways in which frog can reach the top.
long long countWays(int n)
{
long long dp[n];
long long mod=1e9+7;
dp[0] = dp[1] = 1;
dp[2] = 2;
for (int i = 3; i <= n; i++){
dp[i] = ((dp[i - 1] % mod) + (dp[i - 2]%mod) + (dp[i - 3]%mod))%mod;
}
return dp[n]%mod;
}
};
The text was updated successfully, but these errors were encountered:
class Solution
{
public:
//Function to count the number of ways in which frog can reach the top.
long long countWays(int n)
{
long long dp[n];
long long mod=1e9+7;
dp[0] = dp[1] = 1;
dp[2] = 2;
for (int i = 3; i <= n; i++){
dp[i] = ((dp[i - 1] % mod) + (dp[i - 2]%mod) + (dp[i - 3]%mod))%mod;
}
return dp[n]%mod;
}
};
The text was updated successfully, but these errors were encountered: