N-th Tribonacci Number
2 approaches, code in every language
Problem description
The Tribonacci sequence is seeded with T(0) = 0, T(1) = 1, and T(2) = 1. From there on, every term is the sum of the three that come right before it, so T(n) = T(n - 1) + T(n - 2) + T(n - 3) for any n greater than 2.
Given a non-negative index n, return the value of T(n).
Example 1
Input: n = 4
Output: 4
T(3) = 0 + 1 + 1 = 2, and then T(4) = 1 + 1 + 2 = 4.
Example 2
Input: n = 25
Output: 1389537
Constraints
0 ≤ n ≤ 37The answer is guaranteed to fit inside a signed 32-bit integer (at most 2^31 − 1).
Create a free account to see the solution
You get the step-by-step animation, the intuition and clean code in every language. Free, no credit card.
After the pattern
Now solve one you haven't seen.
Three-Day Dispatch Ladder is our own problem on the technique behind N-th Tribonacci Number: a new statement, so there's no answer to remember. Write it in your browser and run it against graded tests.
1,194 problems · 15,062 graded tests · free