Swap Two Numbers
Updated
Problem statement
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