function solution(n,r) {
let answer;
let diff = n-r;
if (diff<r)
r = diff;
let dy = Array.from(Array(n),()=>Array(r).fill(0));
function DFS(n, r) {
if (dy[n-1][r-1]>0) return dy[n-1][r-1];
diff = n-r;
if(diff<r) r = diff;
if(r === 1) return n;
else if(r === n) return 1;
else
return dy[n-1][r-1] = DFS(n-1,r-1) + DFS(n-1,r);
}
answer = DFS(n,r);
return answer;
}
console.log(solution(10,7));