79459810

Date: 2025-02-22 15:13:20
Score: 0.5
Natty:
Report link

As the problem states, imagine you are standing at point A and want to reach point B. There are n stoppers in between, meaning you are not at the first stop and do not want to stop at the last one.

A -> n -> B

To solve this problem efficiently, we store the number of ways in a dp array

int[] dp = new int[n+1]

and use a loop

for(int i=3; i<n+1; i++){

dp[i] = dp[i-1] + dp[i-2] + dp[i-3]

}

Finally, the answer will be stored in dp[n].

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Mayank Mehta