FastPrepFirst N Fibonacci Numbers
Problems/First N Fibonacci Numbers

First N Fibonacci Numbers

Zillow logoZillow● EasyFULLTIMEOAPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Asked at Zillow from 2014 to 2021. Three reports place it in a phone screen. Two others had an online test and then phone interviews, and one had a tech screen and then an onsite; these three do not say which round had this question. The last report does not name the round. The reports came from a new grad candidate and from software candidates who gave no level, among them people applying for mobile and machine learning roles. Most reports name the Fibonacci task without giving its form; two asked the candidate to build the sequence. One wanted a loop instead of recursion, one asked the candidate to improve a first version and then asked more about it, and one talked through other ways to compute the numbers.

The reports do not say where the sequence starts, how large n can be, or how the answer is returned. Here the sequence starts at 0 and 1, the answer is an array holding F(0) through F(n - 1), and n is at most 79, so every value fits in a 64-bit integer. The editorial also covers computing a single number with constant memory, faster methods, and how they compare.

Our version is about 80% 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 an array of the first n Fibonacci numbers in order: [F(0), F(1), ..., F(n - 1)].

Function

firstFibonacciNumbers(n: int) → long[]

Examples

Example 1

n = 5return = [0,1,1,2,3]

F(0) = 0 and F(1) = 1 are given. Then F(2) = 0 + 1 = 1, F(3) = 1 + 1 = 2 and F(4) = 1 + 2 = 3.

Example 2

n = 1return = [0]

Only the first number is asked for, and it is F(0) = 0.

Example 3

n = 2return = [0,1]

The first two numbers are the two starting values, so no sums are needed.

Example 4

n = 10return = [0,1,1,2,3,5,8,13,21,34]

From F(2) on, each number is the sum of the two before it. The last one is F(9) = 13 + 21 = 34.

Constraints

  • 1 <= n <= 79

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
  • Cumulative Fibonacci SumOA · PHONE SCREEN · Seen Aug 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
  • Climbing StairsAmazon · ONSITE INTERVIEW
  • Count Staircase WaysGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Climbing StairsAMD · ONSITE INTERVIEWAMD interview questions
  • Climb Stairs with One, Two, or Three StepsAgoda · ONSITE INTERVIEWAgoda interview questions
  • Climbing StairsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Climbing StairsGoogle · PHONE SCREENGoogle interview questions
  • N-th Fibonacci NumberBank of America · ONSITE INTERVIEWBank of America interview questions
All Zillow interview questionsSee Zillow hiring insights
Saved
class Solution {
    public long[] firstFibonacciNumbers(int n) {
        // Write your code here.
    }
}
Checking account…