The Nth Number in the Fibonacci Sequence
Updated
Problem statement
Position 0 of the Fibonacci sequence holds 0, position 1 holds 1, and from position 2 on each entry adds up the two entries just before it. Return the entry at position n as an int.
Function
fibonacci(n: int) → intExamples
Example 1
n = 7return = 13Position 5 holds 5 and position 6 holds 8, so position 7 holds their sum, 13.
Example 2
n = 0return = 0The sequence starts at position 0 with the value 0.
Example 3
n = 40return = 102334155The sequence grows quickly: position 40 is already over a hundred million, 102334155.
Constraints
0 <= n <= 45
More Capital One interview questions
- Count Records Present in A but Not BPHONE SCREEN · Seen Oct 2026
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
- Maximum Subarray SumPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2025
- Ten-Pin Bowling Frame ScoresPHONE SCREEN · Seen Nov 2023
- Min StackPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2023
- Invert a Binary TreePHONE SCREEN · Seen Dec 2020
- Count How Often a Word Appears in a ParagraphPHONE SCREEN
- In-Memory File System With Directory SizesPHONE SCREEN · ONSITE INTERVIEW
- Pick the K Nearest Grid Points to (0, 0)PHONE SCREEN · ONSITE INTERVIEW
- Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Biased Coin: Probability of Exactly h HeadsAkuna Capital · PHONE SCREENAkuna Capital interview questions
- Dice Sum That Is a Multiple of mSusquehanna International Group (SIG) · PHONE SCREENSusquehanna International Group (SIG) 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
- Count Routes Through a City GridIMC Trading · PHONE SCREENIMC Trading interview questions
Capital One interview experiences
- Capital One Experienced Engineer Power Day and OA: 6 Experiences
- Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
- Capital One TDP Agentic Round (AI Coding): 7 Experiences
- Capital One SWE Power Day, Level Not Reported: 6 Experiences
- Capital One TIP Intern OA and Power Day: 13 Experiences
- Capital One TDP Agentic Power Day: 25 Experiences (Part 1 of 2)