FunctionRacerProblemsRace

The Climb Function

EasyRecursionPython, JavaScript, TypeScript, Java, C++

The climb function C(m, n) is defined for non-negative integers by three rules:

Return C(m, n). The third rule calls the function inside its own argument, so a recursive function is the natural fit; the inputs are kept small enough that no memo table is needed.

For example, C(1, 1) = C(0, C(1, 0)) = C(0, C(0, 2)) = C(0, 3) = 4.

Example 1

m 1
n 1
returns 4

C(1, 0) is C(0, 2) = 3, and then C(0, 3) = 4.

Example 2

m 0
n 5
returns 6

The first rule applies directly: 5 + 1 = 6.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Recursion problems