Nth Tribonacci Number
Let's solve the Nth Tribonacci Number problem using Dynamic Programming.
Statement
Tribonacci numbers are a sequence of numbers where each number is the sum of the three preceding numbers. Your task is to find the Tribonacci number.
The Tribonacci sequence is defined as:
, and for |
---|
The input number, n
, is a non-negative integer.
Let’s say you have to find the fifth Tribonacci number in the sequence. From the sequence defined above, we know that . The sequence will be:
Therefore, the fifth term will be 7.
Constraints:
-
n
- The answer is guaranteed to fit within a 64-bit integer, i.e., answer
Examples
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.