Created
April 21, 2018 15:29
-
-
Save jesuyedavid/39ccf098280890f04ffb400e4eacdff9 to your computer and use it in GitHub Desktop.
Find the number ways to traverse an mXn grid in O(min(m,n)) space.
This file contains hidden or 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
def numWays(n, m): | |
num=[1]*min(n, m) | |
for i in range(max(n,m)-1): | |
for j in range(min(n,m)): | |
if j!=0: | |
num[j]+=num[j-1] | |
return(num[n-1]) | |
print(numWays(2,5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment