Ctrl K

Sum of the Last Three

Easy
A sequence starts with 0, 1, 1 (terms number 0, 1 and 2). Every later term is the sum of the three terms before it: 0, 1, 1, 2, 4, 7, 13, … Given position, return the term with that number.
Example 1
position=5 → 7

The sequence goes 0, 1, 1, 2, 4, 7. Term number 5 is 7 = 1 + 2 + 4.

Example 2
position=1 → 1

The first three terms are given: term number 1 is 1.

Example 3
position=10 → 149
Constraints
  • 0 ≤ position ≤ 37
  • The answer fits in a signed 32-bit integer
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPaving a Garden Path EasySum of the Two Before EasyEvery Bracketing Result MediumShared Pool Race to a Goal MediumThief and Guard Hard
loading Python…
Input
position=5
Expected
7

Run checks the first 3 tests in your browser. Submit checks all 21 tests on the server, hidden ones included.