16. Count Number of Hops
Last updated
Was this helpful?
Last updated
Was this helpful?
The problem can be found at the following link:
I am solving this problem using recursion and memoization.
I maintain an array dp
, where dp[i]
represents the number of ways to reach step i
in the steps.
I started from step 0 and calculate the number of ways to reach the next three steps (1, 2, or 3 steps at a time) recursively until I reach step n
.
This problem is similar to a modified Fibonacci series.
Time Complexity: O(n)
- We calculate the number of ways for each step from 0 to n
only once.
Auxiliary Space Complexity: O(n)
- We use an additional array dp
of size n
.
For discussions, questions, or doubts related to this solution, please visit our . We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star
to the repository.