Cumulative Fibonacci Sum
Updated
Problem statement
The Fibonacci numbers start with F(0) = 0 and F(1) = 1. Every later number is the sum of the two numbers before it: F(i) = F(i - 1) + F(i - 2) for i >= 2.
Given an integer n, return the cumulative sum of the first n Fibonacci numbers: F(0) + F(1) + ... + F(n - 1).
Function
cumulativeFibonacciSum(n: int) → longExamples
Example 1
n = 5return = 7The first five numbers are F(0) = 0, F(1) = 1, F(2) = 1, F(3) = 2 and F(4) = 3. Their sum is 0 + 1 + 1 + 2 + 3 = 7.
Example 2
n = 1return = 0Only F(0) = 0 is added, so the sum is 0.
Example 3
n = 2return = 1The sum is F(0) + F(1) = 0 + 1 = 1.
Example 4
n = 10return = 88The first ten numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, and they add up to 88.
Constraints
1 <= n <= 77
More Zillow Phone Screen questions
- Valid ParenthesesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025
- Build a Hash TableOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2023
- Reversible Run-Length EncodingPHONE SCREEN · Seen Nov 2022
- First Unique Character in a StringOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2022
- First N Fibonacci NumbersOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2021
- Lowest Common Ancestor in a Binary TreePHONE SCREEN · Seen Sep 2019
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2016
- Blackjack Hand ScorePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2016
- FactorialPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2014
- Find the Four Missing Numbers in a FileOA · PHONE SCREEN · Seen Feb 2014
Similar questions at other companies
- Enough Muffins for the LineSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Biased Coin: Probability of Exactly h HeadsAkuna Capital · PHONE SCREENAkuna Capital interview questions
- Probability of Consecutive HeadsSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Count Staircase WaysGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- Climbing StairsGoogle · PHONE SCREENGoogle interview questions
- Count Numbers with Digit SumCisco · OACisco interview questions
- Count Routes Through a City GridIMC Trading · PHONE SCREENIMC Trading interview questions
- Ways to Climb n StairsAdobe · PHONE SCREENAdobe interview questions
- Heads in Fair Coin FlipsJane Street · PHONE SCREENJane Street interview questions
- Climbing StairsBloomberg LP · PHONE SCREENBloomberg LP interview questions