Dear readers, this is a very similar question to that of the previous one, except that instead of counting all the paths, we want the path with minimum moves.
Important Links : Problem Link, Question Video, Solution Video
Climb Stairs With Minimum Moves
Sometimes it's better to leave something alone, to pause, and that's very true of programming.
~ Joyce Wheeler
Dear readers, this is a very similar question to that of the previous one, except that instead of counting all the paths, we want the path with minimum moves.
Important Links : Problem Link, Question Video, Solution Video
Let's understand this first.
If we have:
x moves to go from a to D
y moves to go from b to D
z moves to go from c to D
Then for going from S to D the path with the minimum move will be min(x, y, z) + 1.
We will again make it into 3 states:
java; true";
O(n2)
Here we are running to loops. Outerloop runs n times and the inner loop can run n times in the worst case. And within the inner loop, we are just adding hence we will get constant time. So it's O(n*n) = O(n2).O(n)
Here we are just using one dp[] array of length n+1, to store the results. Thus the space complexity will be O(n+1) = O(n)
With this, we conclude our question of Climb Stairs with Minimum Moves. Hope you have understood the problem. See you in the next problem.