The Tribonacci sequence is defined by T(0) = 0, T(1) = 1, T(2) = 1, and T(n + 3) = T(n) + T(n + 1) + T(n + 2) for n >= 0. Given n, return the value of T(n).
The Tribonacci sequence is defined by T(0) = 0, T(1) = 1, T(2) = 1, and T(n + 3) = T(n) + T(n + 1) + T(n + 2) for n >= 0. Given n, return the value of T(n).
Example 1:
Input: {"n":4}
Output: 4
Constraints:
0≤n≤37
The answer fits in a 32-bit integer, so T(n)≤231−1.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"n":4}
Each Tribonacci term is the sum of the three terms before it. We want T(4).