FastPrepSwap Two Integers
Problems/Swap Two Integers

Swap Two Integers

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, the candidate was asked how to exchange the values of two numbers.

The report does not say whether a temporary variable was allowed, and gives no limits. Here, the numbers are 32-bit integers, any method is allowed, and you return the two values in their new order.

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

You are given two integers a and b. Swap their values: afterwards a should hold the old value of b, and b the old value of a.

Return the two values after the swap as an array [a, b], which is the original [b, a]. Any way of swapping is allowed, including a temporary variable.

Function

swapNumbers(a: int, b: int) → int[]

Examples

Example 1

a = 12b = -40return = [-40,12]

After the swap a holds -40 and b holds 12.

Example 2

a = 2147483647b = 5return = [5,2147483647]

The values trade places. Note that a + b = 2147483652 is larger than the largest 32-bit integer, 2147483647.

Example 3

a = 0b = 0return = [0,0]

Both values are 0, so the result looks the same as the input.

Constraints

  • -2^31 <= a, b <= 2^31 - 1

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[] swapNumbers(int a, int b) {
        // write your code here
    }
}
Checking account…