Skip to content
Decoder

N-th Tribonacci Number

Easy

Problem

The Tribonacci sequence starts T0 = 0, T1 = 1, T2 = 1, and every later term is the sum of the three terms before it: T(n) = T(n - 1) + T(n - 2) + T(n - 3). Return T(n).

Example 1

Input
n = 4
Output
4
Why
0, 1, 1, 2, 4

Example 2

Input
n = 25
Output
1389537

Example 3

Input
n = 0
Output
0

Constraints

  • 0 <= n <= 37
  • The answer fits in a 32-bit integer.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.