FunctionRacerProblemsRace

Rabbit Pairs

EasyDynamic programmingPython, JavaScript, TypeScript, Java, C++

You start with one newborn pair of rabbits. A pair needs one full month to mature; from its second month of life on, every month it produces a litter of litter new pairs. Rabbits never die. Return the number of pairs alive in month months, where month 1 is the month you start with the newborn pair.

Example 1

months 5
litter 1
returns 5

With litter 1 this is Fibonacci: 1, 1, 2, 3, 5.

Example 2

months 4
litter 3
returns 7

1, 1, 4, 7.

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 Dynamic programming problems