FastPrepCumulative Fibonacci Sum
Problems/Cumulative Fibonacci Sum

Cumulative Fibonacci Sum

Zillow logoZillow● EasyFULLTIMEOAPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Asked at Zillow from 2014 to 2021. Three reports place it in a screen: one candidate had two phone screens and does not say which one had this question, one had a phone coding screen and one had a technical screen of about an hour. The fourth report had an online code exercise. One candidate applied for a senior software engineer job; the other three applied for software development engineer jobs and gave no level. One report gives the definition: add the Fibonacci numbers from the start through n - 1. In the hour-long screen the interviewer asked for something faster than the candidate's O(n) solution; the report does not say which faster method was expected. In the phone coding screen the candidate wrote the code in C# and then talked through other ways to write it and their time and space costs.

The reports do not say where the sequence starts, how large n can be, or whether the code reads input or is a function. Here the sequence starts at F(0) = 0 and F(1) = 1, and we read "through n - 1" as the terms F(0) through F(n - 1), so n counts the terms. The code is a function that gets n as an argument and returns the sum. n is at most 77, so the sum stays below 2^53 and is exact in every language, including JavaScript; it still needs a 64-bit integer. For the follow-up, the editorial shows a method whose time grows with log n.

Our version is about 85% the same as the reported question.

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) → long

Examples

Example 1

n = 5return = 7

The 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 = 0

Only F(0) = 0 is added, so the sum is 0.

Example 3

n = 2return = 1

The sum is F(0) + F(1) = 0 + 1 = 1.

Example 4

n = 10return = 88

The 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
All Zillow interview questionsSee Zillow hiring insights
Saved
class Solution {
    public long cumulativeFibonacciSum(int n) {
        // Write your code here.
    }
}
Checking account…