Binomial Coefficient nCr mod 10⁹+7

Medium · Math & Number Theory · about 20 minutes

Asked at Google, Amazon, Databricks.

Given n and r (0 ≤ n ≤ 10⁵), return the number of ways to choose r items out of n, modulo 1 000 000 007. Return 0 if r > n.