Back to Practice Dashboard
Competitive ProgrammingEasy

Binomial Coefficient

Learn how to solve the 'Binomial Coefficient' problem. This detailed resource details brute force and optimized approaches.

Problem Statement

Easy

Write a function binomial_coefficient(n, r) that computes the binomial coefficient nCr. If r > n or r < 0, return 0.

Constraints
  • 0 <= n <= 1000
  • 0 <= r <= 1000

Examples

Example 1
Input
binomial_coefficient(5, 2)
Output
10
Explanation

5C2 = 5! / (2! * 3!) = 10.

Example 2
Input
binomial_coefficient(10, 3)
Output
120
Explanation

10C3 = 10! / (3! * 7!) = 120.

Need a Hint?
Define subproblem states, establish the recurrence relation, and use memoization (top-down) or tabulation (bottom-up).
Edge Cases to Watch
  • Empty list or null input variables
  • Single item lists/arrays
  • Extremely large input bounds causing integer or stack overflow

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor