First N Fibonacci Numbers
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 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