FastPrepFirst N Prime Numbers
Problems/First N Prime Numbers

First N Prime Numbers

Bank of America logoBank of America● EasyNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported by a new grad candidate who applied through campus hiring for an Apprentice role at Bank of America. In the second round, a technical interview of 20 to 30 minutes, one of the tasks was to output the first fifteen primes.

Here, the count n can be anything from 1 to 2,000, and you return the primes in an array. Example 1 is the reported case, n = 15.

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

A prime number is an integer greater than 1 whose only positive divisors are 1 and itself.

Given an integer n, return an array of the n smallest prime numbers in increasing order.

Function

firstPrimes(n: int) → int[]

Examples

Example 1

n = 15return = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]

These are the first 15 primes. On the way to 47, 1 is skipped because a prime must be greater than 1. The even numbers after 2 and the odd numbers 9, 15, 21, 25, 27, 33, 35, 39 and 45 are skipped because each of them has a divisor other than 1 and itself.

Example 2

n = 1return = [2]

2 is the smallest prime, and the only even one.

Example 3

n = 7return = [2,3,5,7,11,13,17]

The seventh prime is 17. Between 2 and 17, the odd numbers 9 = 3 * 3 and 15 = 3 * 5 are not prime.

Constraints

  • 1 <= n <= 2000

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
  • Factorial of a NumberONSITE INTERVIEW · Seen Oct 2023
  • Palindrome String CheckONSITE INTERVIEW · Seen Sep 2023

Similar questions at other companies

  • Confusing Bib NumbersVerily · ONSITE INTERVIEW
  • Plus OneDruva · ONSITE INTERVIEW
  • Rotate a Flat Image ClockwiseGoogle · ONSITE INTERVIEWGoogle interview questions
  • Matrix MultiplicationeBay · ONSITE INTERVIEWeBay interview questions
  • Maximum Product of Three IntegersPelatro · ONSITE INTERVIEW
  • Climbing StairsAmazon · ONSITE INTERVIEW
  • Maximum 69 NumberHSBC · ONSITE INTERVIEWHSBC interview questions
  • Roman to IntegerKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Exact-Sixty Dice Game ValueJane Street · ONSITE INTERVIEWJane Street interview questions
  • Find the Missing Number from 1 to nHyperVerge · ONSITE INTERVIEW

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 int[] firstPrimes(int n) {
        // write your code here
    }
}
Checking account…