grandest staircase foobar 1

grandest staircase foobar

def solution(n):
    m = [[0 for i in range(n + 1)] for j in range(n + 1)]
    m[0][0] = 1  # base case
    for stair in range(1, n + 1):
	    for left in range(0, n + 1):
	        m[stair][left] = m[stair - 1][left]
	        if left >= stair:
	            m[stair][left] += m[stair - 1][left - stair]
	          	
    return m[n][n] -1

Here is what the above code is Doing:
1. We create a matrix m[n+1][n+1]
2. We initialize the first row and first column to 0
3. We initialize the first element of the matrix to 1
4. We iterate over the rows of the matrix
5. We iterate over the columns of the matrix
6. We set the value of the current element to the value of the element above it
7. If the current column is greater than or equal to the current row, we add the value of the element above and to the left of the current element
8. We return the value of the last element in the matrix minus 1

Similar Posts