FastPrepN-th Fibonacci Number
Problems/N-th Fibonacci Number

N-th Fibonacci Number

Bank of America logoBank of America● EasyNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported by two Bank of America new grads from campus hiring drives, in a live technical round after the video step. One candidate had to write Fibonacci code twice, once with a loop and once with recursion; the other was asked to code the Fibonacci series.

The reports give no examples, limits or exact output. Here, the function returns one term, F(n), of the sequence that starts 0, 1, for n from 0 to 50, and the solution shows both the loop and the recursive versions. Printing the whole series is covered as a follow-up.

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

The Fibonacci sequence starts with 0 and 1, and each term after that is the sum of the two terms just before it: 0, 1, 1, 2, 3, 5, 8, ...

Number the terms from 0, so F(0) = 0, F(1) = 1 and F(n) = F(n - 1) + F(n - 2) for n >= 2. Given n, return F(n).

For the larger values of n the answer does not fit in a 32-bit integer, so return it as a 64-bit integer.

Function

fibonacci(n: int) → long

Examples

Example 1

n = 9return = 34

The terms from F(0) to F(9) are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34. The last one is 34.

Example 2

n = 0return = 0

F(0) is the first term, 0.

Example 3

n = 2return = 1

F(2) = F(1) + F(0) = 1 + 0 = 1.

Constraints

  • 0 <= n <= 50

More Bank of America Onsite Interview questions

  • Centered Star PyramidONSITE INTERVIEW · Seen Nov 2025
  • Employees Without a ManagerONSITE INTERVIEW · Seen Nov 2025
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2025
  • Reverse Each Word in a SentenceONSITE INTERVIEW · Seen Nov 2025
  • Second Highest SalaryONSITE INTERVIEW · Seen Nov 2025
  • Three Numbers That Add Up to a TargetONSITE INTERVIEW · Seen Apr 2025
  • Duplicate RowsONSITE INTERVIEW · Seen Oct 2023
  • Factorial of a NumberONSITE INTERVIEW · Seen Oct 2023
  • Palindrome String CheckONSITE INTERVIEW · Seen Sep 2023
  • Second Largest Element in an ArrayONSITE INTERVIEW · Seen Jun 2023

Similar questions at other companies

  • Fibonacci with Input ValidationMorgan Stanley · ONSITE INTERVIEWMorgan Stanley interview questions
  • Every Result of Grouping an ExpressionC3.ai · ONSITE INTERVIEWC3.ai interview questions
  • Fibonacci NumberMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Climbing StairsAmazon · ONSITE INTERVIEW
  • Climbing StairsAMD · ONSITE INTERVIEWAMD interview questions
  • Climb Stairs with One, Two, or Three StepsAgoda · ONSITE INTERVIEWAgoda interview questions
  • Fibonacci NumberJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
  • Climbing StairsExpedia · PHONE SCREEN · ONSITE INTERVIEWExpedia interview questions
  • The Nth Number in the Fibonacci SequenceCapital One · PHONE SCREEN · ONSITE INTERVIEWCapital One interview questions
  • Count Complete Tic-Tac-Toe GamesDecagon · PHONE SCREEN · ONSITE INTERVIEWDecagon interview questions

Bank of America interview experiences

  • Bank of America interviews · December 2025
  • Bank of America OA · December 2025
  • Bank of America interviews · September 2026
  • Bank of America OA · September 2026
All Bank of America interview questionsSee Bank of America hiring insights
Saved
class Solution {
    public long fibonacci(int n) {
        // write your code here
    }
}
Checking account…