Skip to content

1137. N-th Tribonacci Number #219

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

The Tribonacci sequence is a variation of the Fibonacci sequence, where each number is the sum of the previous three numbers. In this problem, you're tasked with calculating the N-th Tribonacci number using the given recurrence relation:

  • T0 = 0, T1 = 1, T2 = 1
  • Tn+3 = Tn + Tn+1 + Tn+2 for n ≥ 0

The goal is to compute Tn efficiently, considering the constraints 0 ≤ n ≤ 37.

Key Points

  1. Dynamic Programming Approach: Since each Tribonacci number depends on the previous three, this is an excellent candidate for dynamic programming.
  2. Space Optimization: Instead of maintaining a full array for all intermediate values, we only need to track the last three numbers.
  3. Constraints: The value of n is r…

Replies: 1 comment 2 replies

Comment options

mah-shamim
Jan 6, 2025
Maintainer Author

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Jan 6, 2025
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested easy Difficulty
2 participants