I am getting a wrong answer in one of the test cases for A=15 and B=9 , i think if there is an overflow problem


#1

int Solution::uniquePaths(int A, int B) {
if(A==1 && B==1)
{
return 1;
}
if(A==0 || B==0)
{
return 1;
}
int dp[A][B];
for(int j=0;j<B;j++)
{
dp[A-1][j] =1;
}
for(int i=0;i<A;i++)
{
dp[i][B-1] =1;
}

for(int i= A-2 ; i>=0;i--)
{
	for(int j=B-2;j>=0;j--)
	{
		dp[i][j] = ((dp[i+1][j]) +(dp[j+1][i]));
	}
}
int ans = dp[0][0];
return ans;

}


#2

check your indexing where you are putting the value in the dp. it will be dp[i][j+1]


#3
int Solution::uniquePaths(int A, int B) {

vector<vector<int> > path(A,vector<int>(B,0));

for(int i=0;i<B;i++) path[0][i]=1;
for(int i=0;i<A;i++) path[i][0]=1;

for(int i=1;i<A;i++)
{
    for(int j=1;j<B;j++)
    {
        path[i][j]=path[i-1][j]+path[i][j-1];
    }
}

return path[A-1][B-1];
}