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 = 4
Output:4
Explanation:

T(4) = T(3) + T(2) + T(1) = 2 + 1 + 1 = 4.

Input:n = 0
Output:0
Explanation:

T(0) = 0 by definition. This is the base case where n = 0.

Input:n = 6
Output:13
Explanation:

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

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!