Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-329

Ballot Paths Never Behind

Problem

The number of monotone paths from (0, 0) to (n, n) that never go above the diagonal is the Catalan number C(2n, n) / (n + 1).

Given n, return the count.

Hint

The reflection principle gives 1 / (n + 1) of all paths.

Test cases

case 1
in: [1]
expected: 1
case 2
in: [3]
expected: 5
case 3
in: [4]
expected: 14
Starter codePython
def ballot_paths_never_behind(n):
    # Your code here
    pass

3 test cases · run your code against them in the editor