FastPrepFactorial of a Number
Problems/Factorial of a Number

Factorial of a Number

Bank of America logoBank of America● EasyNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported by a Bank of America new grad from a campus drive, in the first technical round, a 30-minute interview after the recorded video interview. The candidate had to code the factorial of a number in Java and then explain, step by step, how the program runs.

The report gives no examples, limits or exact output. Here, n is from 0 to 20, so the answer fits in a 64-bit integer, and the solution shows both the recursive and the loop versions with a walk through the calls. Larger n, which needs big-number arithmetic, is covered as a follow-up.

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

Given a non-negative integer n, return n! (read "n factorial"), the product of all whole numbers from 1 to n. By definition, 0! = 1.

The answer grows quickly and does not fit in a 32-bit integer once n reaches 13, so return it as a 64-bit integer.

Function

factorial(n: int) → long

Examples

Example 1

n = 6return = 720

6! = 1 * 2 * 3 * 4 * 5 * 6 = 720.

Example 2

n = 0return = 1

0! is 1 by definition: it is the product of no numbers.

Example 3

n = 13return = 6227020800

12! = 479,001,600, so 13! = 13 * 479,001,600 = 6,227,020,800. This is larger than the biggest 32-bit integer, 2,147,483,647.

Constraints

  • 0 <= n <= 20

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
  • N-th Fibonacci NumberONSITE 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
  • Palindrome String CheckONSITE INTERVIEW · Seen Sep 2023
  • Second Largest Element in an ArrayONSITE INTERVIEW · Seen Jun 2023

Similar questions at other companies

  • Multiply Without the Multiplication OperatorMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Fibonacci with Input ValidationMorgan Stanley · ONSITE INTERVIEWMorgan Stanley interview questions
  • FactorialAMD · ONSITE INTERVIEWAMD interview questions
  • Path Between Two Nodes of a Fibonacci TreeDatabricks · ONSITE INTERVIEWDatabricks interview questions
  • Power with Integer ExponentsLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • Integer to English Words: Up to 20 DigitsPeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
  • Every Result of Grouping an ExpressionC3.ai · ONSITE INTERVIEWC3.ai interview questions
  • Pow(x, n)Bloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Integer Power Without a Library CallExpedia · ONSITE INTERVIEWExpedia interview questions
  • Josephus SurvivorApple · ONSITE INTERVIEWApple 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 factorial(int n) {
        // write your code here
    }
}
Checking account…