Back to problems Sign in to unlock
Leetcode
Easy
Dynamic Programming
Recursion
Math
N Th Tribonacci Number
Compute the -th Tribonacci number, where each term is the sum of the previous three terms.
Acceptance 0%
Problem Statement
Problem
The Tribonacci sequence is defined similarly to Fibonacci, but each term depends on the previous three terms.
Let:
- For ,
Given an integer , return the -th Tribonacci number.
Goal
Write a function that computes the value of efficiently.
Input Format
- One integer
Output Format
- Return a single integer: the -th Tribonacci number
Constraints
- The result fits in a 32-bit signed integer
Examples
Sample cases returned by the problem API.
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 .
Show 1 more example
Example 3
Input
n = 0
Output
0
Explanation
By definition, .
Premium problem context
Unlock deeper context for this problem
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.
Guided hints
Editorial and discussion links
Concept map and variants
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.