AlgoDesign

Number of moves to climb stairs

1from functools import lru_cache
2class Solution:
3    def numberOfMovesToClimbStairs(self, n, k):
4        return self.topDown(n, k, 0)
5    
6    @lru_cache(None)
7    def topDown(self, n, k, stair):
8        if stair == n: return 1
9        if stair > n: return 0
10        res = 0
11        for i in range(1, min(k, n - stair) + 1):
12            if stair + i <= n: res += self.topDown(n, k, stair + i)
13        return res