Continue learning
Practice related DSA questions in the same topic.
Count ordered ways to reach target steps using hops of one or two. The values list is unused.
Count ordered ways to reach target steps using hops of one or two. The values list is unused.
def solve(values, target): prev = 1 curr = 1 i = 2 while (i <= target): ways = (prev + curr) prev = curr curr = ways i = (i + 1) return currEmpty array
Combine the two predecessor route counts.
Combine the two predecessor route counts.
Every route to a landing arrives from one of the previous two landings.
Each route ends with either a one-step or two-step hop. Add the counts at those two predecessor stairs.
O(t) time · O(1) auxiliary space
Worked example · {"values":[],"target":6} ⇒ 13
Edge case 1 · {"values":[],"target":0} ⇒ 1
Edge case 2 · {"values":[],"target":1} ⇒ 1
The starting floor has one empty route, so ways(0) equals one.
What if three-step hops were allowed?