Competitive ProgrammingEasy

Binomial Coefficient

Detailed guide and Python implementation for the 'Binomial Coefficient' problem.

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?
Consider using Dynamic Programming-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

Ready to Solve?

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

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.