Grokking 75: Top Coding Interview Questions
Ask Author
Back to course home

0% completed

Vote For New Content
N-th Tribonacci Number (easy)
On this page

Problem Statement

Examples

Try it yourself

Problem Statement

The Tribonacci sequence T<sub>n</sub> is defined as follows:

T<sub>0</sub> = 0, T<sub>1</sub> = 1, T<sub>2</sub> = 1, and T<sub>n + 3</sub> = T<sub>n</sub> + T<sub>n+1</sub> + T<sub>n+2</sub> for n >= 0.

Given an integer n, return the n<sup>th</sup> Tribonacci term T<sub>n</sub>.

Examples

Example 1

  • Input: n = 5
  • Expected Output: 7
  • Justification: The sequence up to the 5th term is [0, 1, 1, 2, 4, 7]. The 5th term is 7.

Example 2

  • Input: n = 8
  • Expected Output: 44
  • Justification: The sequence up to the 8th term is [0, 1, 1, 2, 4, 7, 13, 24, 44]. The 8th term is 44.

Example 3

  • Input: n = 10
  • Expected Output: 149
  • Justification: The sequence up to the 10th term is [0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149]. The 10th term is 149.

Constraints:

  • 0 <= n <= 37
  • The answer is guaranteed to fit within a 32-bit integer, ie. answer <= 2<sup>31</sup> - 1.

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Like the course? Get enrolled and start learning!

On this page

Problem Statement

Examples

Try it yourself