1 2 3 4 5 6 7 8 9 10 11 12 | function solution(balls, share) { const memo = new Array(balls + 1); memo[0] = BigInt(1); memo[1] = BigInt(1); memo[2] = BigInt(2); for (let i = 3; i < memo.length; i++) { memo[i] = BigInt(i) * memo[i - 1]; } return memo[balls] / (memo[balls - share] * memo[share]); } |