Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

N-th Tribonacci Number

XPChallenge Points: 10
levelLevel: Easy

The Tribonacci sequence extends the idea of Fibonacci by summing the previous three terms instead of two.

It begins with:

  • T₀ = 0

  • T₁ = 1

  • T₂ = 1

For all n ≥ 0:

Tₙ₊₃ = Tₙ + Tₙ₊₁ + Tₙ₊₂

Your task is to compute and return Tₙ for a given integer n.

Example 1:

Input: n = 0

Output: 0

Example 2:

Input: n = 3

Output: 2

Explanation:

T₃ = T₀ + T₁ + T₂ = 0 + 1 + 1 = 2

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result