Recursion: Davis' Staircase Discussions | | HackerRank

Recursion: Davis' Staircase

  • + 0 comments

    Python with dynamic programming

    def stepPerms(n, memo=None):
        if memo is None:
            memo = [None] * (n + 1)
        if n == 0:
            return 1
        if n < 0:
            return 0
        if memo[n] is None:
            memo[n] = stepPerms(n-1, memo) + stepPerms(n-2, memo) + stepPerms(n-3, memo)
        return memo[n]