C++ Solution using Combinatorics


#1
long long int factorial(int n, int start)
{
    long long int fac=1;
    for(int i=start+1;i<=n;i++)
        fac*=i;
    return fac;
}

int nCr(int n, int r)
{
    long long int a,b;
    a=factorial(n,max(r,n-r));
    b=factorial(min(r,n-r),1);
    return a/b;
}

int Solution::uniquePaths(int A, int B)
{
    return nCr(A+B-2,A-1);
}