The Catalan Calculator
HardAcc. 75.6%
+40 XP 20
Counting Structur
Catalan numbers ($C_n$) appear in many counting problems, like "how many ways can we arrange $N$ pairs of parentheses?" Formula: $C_n = rac{1}{n+1} inom{2n}{n}$ or via the iterative product: $prod_{i=1}^n rac{n+i}{i}$.
The Assignment
Your function receives a parameter n.
- Initialize
catalanto 1. - Use a loop from 1 to
n. - In each step, calculate:
catalan = catalan * (n + i) / i. - Finally, divide by (n + 1) (though using the product formula $prod rac{n+k}{k}$ is often cleaner).
- Print the integer result (
Math.round).
01EXAMPLE 1
Input
n = 3Output
5Explanation: C0=1, C1=1, C2=2, C3=5.
Constraints
- Use a single loop to compute the product.
- Return a whole number.
MathLoopsCombinatorics
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
n3
Expected Output
5
Click RUN to test your solution