Use dynamic programming to solve this


#1

int dp[a][b];
set first row and column=1;
dp[i][j] = dp[i-1][j] + dp[i][j-1];
return dp[a-1][b-1];


#2

U can use 1D array for storage instead of using 2D array,
Just use row array and then store value accordingly.
int dp[a]=1
dp[i]=dp[i]+dp[i+1];