InterviewBit Grid Unique Path  

by ne on 2022-02-16 under Algo/DS/Problems tagged with interviewbit

This problem is a property of InterviewBit (www.interviewbit.com). Full details of the question, and if you want to try it out yourself, proceed to interviewbit : https://www.interviewbit.com/problems/grid-unique-paths/
Here's the implementation:

public class Solution {
    public int uniquePaths(int x, int y) {
        if(x==y && x==1) return 1;
        return rec(x-1,y-1);
    }
    
    private int rec(int toX, int toY){
        if(toX==0 && toY>0) return 1;
        if(toY==0 && toX>0) return 1;
        return rec(toX-1,toY) + rec(toX,toY-1);
    }
}