Description
The Tribonacci sequence T(n) is defined as: T(0) = 0, T(1) = 1, T(2) = 1, and T(n) = T(n-1) + T(n-2) + T(n-3) for n > 2. Given n, return the value of T(n).
Examples
Input:
n = 4Output:
4Explanation:
T(4) = T(3) + T(2) + T(1) = 2 + 1 + 1 = 4.
Input:
n = 0Output:
0Explanation:
T(0) = 0 by definition. This is the base case where n = 0.
Input:
n = 6Output:
13Explanation:
T(6) = T(5) + T(4) + T(3) = 7 + 4 + 2 = 13. Working backwards: T(3) = 2, T(4) = 4, T(5) = T(4) + T(3) + T(2) = 4 + 2 + 1 = 7.
Constraints
- •
0 ≤ n ≤ 37