Skip to content

N-th Tribonacci Number

EasyDynamic Programming
Decode it first. Clues, constraints, pattern and plan before any code.

The Tribonacci sequence starts T0 = 0, T1 = 1, T2 = 1, and every later term is the sum of the three terms before it: T(n) = T(n - 1) + T(n - 2) + T(n - 3). Return T(n).

n = 4   →  4         (0, 1, 1, 2, 4)
n = 25  →  1389537
n = 0   →  0

Constraints

  • 0 <= n <= 37
  • The answer fits in a 32-bit integer.