Created
December 20, 2018 14:09
-
-
Save priyankvex/b67cf0ad898dd821126a6160f8ff7642 to your computer and use it in GitHub Desktop.
Scamming the coding interview: Problem 008: Number of ways in the matrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Scamming the coding interview | |
""" | |
def get_number_of_ways(n, m): | |
matrix = [ | |
[0 for j in range(0, m)] for i in range(0, n) | |
] | |
for i in range(0, n): | |
matrix[0][i] = 1 | |
for i in range(0, m): | |
matrix[i][0] = 1 | |
for i in range(1, n): | |
for j in range(1, m): | |
matrix[i][j] = matrix[i-1][j] + matrix[i][j-1] | |
return matrix[n-1][m-1] | |
if __name__ == '__main__': | |
n = 5 | |
m = 5 | |
number_of_ways = get_number_of_ways(n, m) | |
print(number_of_ways) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment