Created
August 5, 2015 18:54
-
-
Save viveksyngh/842f7e796c47df4a9771 to your computer and use it in GitHub Desktop.
Find number of different possible path from Start to Finsih
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
#A robot is located at the top-left corner(Start) of an A x B grid | |
#The robot can only move either down or right at any point in time. | |
#The robot is trying to reach the bottom-right(Finish) corner of the grid | |
#How many possible unique paths are there ? | |
def nCr(self, n, r) : | |
f = math.factorial | |
return f(n)/f(r)/f(n -r) | |
def uniquePaths(self, A, B): | |
return self.nCr(A+B-2, B -1) | |
#Input : A = 2, B = 2 | |
#Output : 2 | |
#2 possible routes : (0, 0) -> (0, 1) -> (1, 1) | |
# OR : (0, 0) -> (1, 0) -> (1, 1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment