X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
nCr
Easy Accuracy: 55.92% Submissions: 922 Points: 2

Find nCr for given n and r.
As answer can be very large, compute it modulo 109 + 7.

Example 1:

Input: n = 3, r = 2
Output: 3
Explanation: 3C2 = 3 

â€‹Example 2:

Input: n = 4, r = 2
Output: 6
Explanation: 4C2 = 6 

You don't need to read input or print anything. Your task is to complete the function ncr() which takes n andas inputs and returns the answer modulo 109 + 7.

Expected Time Complexity: O(n * log n)
Expected Auxiliary Space: O(n)

Constraints:
1 ≤ r, n ≤ 105

We are replacing the old Disqus forum with the new Discussions section given below.