2 line code xD (in C)


#1

int uniquePaths(int A, int B)
{
if(A==1 || B==1) return 1;
else return uniquePaths(A-1, B) + uniquePaths(A, B-1);
}


#2

You can still optimize this. You are calculating some subproblems repeatedly. Think how can you cut short them.


#3

Please don’t put the solution in the problem discussion please.Put it in the solution discussion.


#4

We can use the logic of LCS:
image


#5

You don’t need a 2d array here, 1d array is good enough.