Show problems as
Classic problem #1137EasyMathDynamic ProgrammingMemoization

N-th Tribonacci Number

Real-world version: Three-Day Dispatch Ladder
Tracked in this browser only
Read N-th Tribonacci Number on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

Learn the pattern firstBasic Recursive Functions · Recursion, animated step by step

A courier depot keeps a daily log of how many vans it sent out, numbering days from 0.

The log opens with a quiet day: no vans left the yard on day 0. Exactly one van left on day 1, and exactly one left on day 2. From day 3 onward the depot's rule is fixed: the count for a day is the three counts of the days right before it added together.

Given a day number day, return the number of vans the log shows for that day.

Examples

Example 1

Input
day = 0
Output
0

Day `0` is the quiet day the log opens with, so nothing left the yard.

Example 2

Input
day = 7
Output
24

Days `4` through `6` show 4, 7 and 13 vans, and day `7` follows from those three.

Example 3

Input
day = 26
Output
2555757

The counts climb quickly once the depot's rule takes over, and day `26` is a six-figure count.

Constraints

  • 0 <= day <= 37
  • The count for the requested day is guaranteed to fit in a signed 32-bit integer, so it is at most 2^31 - 1.

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def vans_dispatched(day: int) -> int:
Java
public int vansDispatched(int day)