Triple Step

8.1 Triple Step: A child is running up a staircase with n steps and can hop either 1 step, 2 steps, or 3 steps at a time. Implement a method to count how many possible ways the child can run up the stairs.

BF: Every step in the tree, we can branch out to 1 to 2 or 3 steps from our current step. The number of root to leaf paths are the total number of steps we could take.

DP: Notice the overlapping subtrees in the image below. Store these results as the total number of root to leaf paths in that subtree.

Python BF and DP Memiozation:

Last updated

Was this helpful?