Compute the -th Tribonacci number, where each term is the sum of the previous three terms.
The Tribonacci sequence is defined similarly to Fibonacci, but each term depends on the previous three terms.
Let:
Given an integer , return the -th Tribonacci number.
Write a function that computes the value of efficiently.
Example 1
Input
n = 4
Output
4
Explanation
The sequence starts 0, 1, 1, 2, 4, ... so .
Example 2
Input
n = 25
Output
1389537
Explanation
Using the recurrence repeatedly gives .
Example 3
Input
n = 0
Output
0
Explanation
By definition, .
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.