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 

Your Task:  
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.
Click here to view old Disqus comments.


to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

nCr

Output Window