Facebook Pixel

N-th Tribonacci Number

Problem Statement

The Tribonacci sequence extends the Fibonacci concept by summing the three previous numbers instead of two. The sequence is defined as:

  • T(0) = 0
  • T(1) = 1
  • T(2) = 1
  • For n ≥ 3: T(n) = T(n-1) + T(n-2) + T(n-3)

Given an integer n, return the value of T(n).

Input Format

A single integer n where 0 ≤ n ≤ 37.

Output Format

A single integer representing T(n).

Examples

Example 1:

Input: n = 4
Output: 4

The sequence starts: 0, 1, 1, 2, 4, 7, 13, 24... T(4) = T(3) + T(2) + T(1) = 2 + 1 + 1 = 4

Example 2:

Input: n = 25
Output: 1389537
Invest in Yourself
Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.
Go Pro