FastPrepSwap Two Numbers
Problems/Swap Two Numbers

Swap Two Numbers

Google logoGoogle● EasyINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The firsthand report says the interviewer followed up by asking how to swap two numbers. We added integer limits and a function that returns an array. We allow ordinary temporary storage, because the report states no limit on the technique. Our version keeps the reported follow-up at about 94%.

Given two integers first and second, return a two-element array containing their values after they are swapped.

The returned array must be [second, first]. You may use ordinary temporary storage; no arithmetic-only or bitwise-only technique is required.

Function

swapNumbers(first: int, second: int) → int[]

Examples

Example 1

first = 7second = -3return = [-3,7]

The second value becomes the first element, and the first value becomes the second element.

Example 2

first = 5second = 5return = [5,5]

Equal values remain equal after their positions are exchanged.

Example 3

first = -1000000000second = 1000000000return = [1000000000,-1000000000]

The operation simply reverses the two boundary values without arithmetic.

Constraints

  • -10^9 <= first <= 10^9
  • -10^9 <= second <= 10^9

More Google Phone Screen questions

  • Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
  • Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Logger Rate Limiter with Every-Arrival HistoryPHONE SCREEN · Seen Nov 2026
  • Minimum Total Layover WaitPHONE SCREEN · Seen Nov 2026
  • Reach a Destination Through Scheduled FlightsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
  • Search and Format ContactsAdyen · PHONE SCREENAdyen interview questions
  • Array-Backed Set Without Library CollectionsOde with Anthropic · PHONE SCREEN
  • Paginate Retained Conversation HistorySierra · PHONE SCREENSierra interview questions
  • Validate a Chess Bishop, Rook, or Queen MoveGlean · PHONE SCREENGlean interview questions
  • Count Distinct Underwriting PII ValuesAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
  • Apply Affine Array TransformationsByteDance · PHONE SCREENByteDance interview questions
  • Match a Variadic Function SignatureConfluent · PHONE SCREENConfluent interview questions
  • Bounded IPv4 FilterAmazon · PHONE SCREEN
  • Partition and Group Values by ParityEPAM · PHONE SCREENEPAM interview questions

Interview reports that mention this question

  • Google SWE Intern Onsite Questions: 16 Experiences (Part 2 of 3)

Google interview experiences

  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
  • Google AI Coding Interview and AI OA: 2 Experiences
  • Google SWE Intern Interview Results Timeline: 13 Experiences
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[] swapNumbers(int first, int second) {
        // Write your code here.
    }
}
Checking account…