Skip to content
BytePatterns

Nth Tribonacci Number

EasyRecursion#recurrence#rolling-state~10m

Problem

The Tribonacci sequence starts with T(0) = 0, T(1) = 1 and T(2) = 1, and every later term is the sum of the three before it: T(n) = T(n - 1) + T(n - 2) + T(n - 3). Given n with 0 ≤ n ≤ 37, return T(n).

Examples

Input:  n = 4
Output: 4
Why:    the sequence runs 0, 1, 1, 2, 4
Input:  n = 25
Output: 1389537
Input:  n = 0
Output: 0
Why:    edge case, the first seed value

Hints

0 / 3

Stuck on the idea rather than the code? Factorial and Fibonacci covers it.