Swap Two Numbers Problem Statement

Given two integers a and b, your task is to swap these numbers and output the swapped values.

Input:

The first line contains a single integer 't', representing the number of test cases.
Each subsequent line contains two space-separated integers, 'a' and 'b'.

Output:

For each test case, output the swapped values in a single line as 'b' followed by 'a'.

Example:

Input:
2
3 4
5 6
Output:
4 3
6 5

Constraints:

  • 1 <= 't' <= 102
  • -105 <= 'a', 'b' <= 105
  • Time Limit: 1 sec

Note:

You do not need to print anything; it has already been taken care of. Just implement the specified function to return the results.

AnswerBot
4mo

Swap two numbers 'a' and 'b' and output the swapped values.

  • Create a temporary variable to store one of the numbers

  • Assign the value of 'a' to 'b' and the temporary variable to 'a'

  • Output the swapped val...read more

HIMANSHU GUPTA
2mo
function swap(a, b){ const temp = a; a = b; b = temp; return [a, b] }
Help your peers!
Select
Add answer anonymously...

Cybage React Developer interview questions & answers

A React Developer was asked Q. How is state changed in Redux?
A React Developer was asked Q. What are callbacks in JavaScript?
A React Developer was asked Q. How can we structure the top-level directories in Redux?

Popular interview questions of React Developer

A React Developer was asked Q1. How is state changed in Redux?
A React Developer was asked Q2. What are callbacks in JavaScript?
A React Developer was asked Q3. How can we structure the top-level directories in Redux?
Cybage React Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits