O(N) solution and O(1) extra space using pascal triangle


#1

If you use Permutation and combination you will find the final ans will be (A+B-2)!/((A-1)!*(B-1)!)
which is (A+B-2)C(A-1) this can be calculated in O(N) time and O(1) space using pascal triangle.