Dsa
Arrays
Easy
Alternate Pair Swap
Write a program that takes an integer array and swaps each pair of adjacent elements. If the array contains an odd number of elements, leave the last element as it is. The input will be structured as follows:
- The first line will contain n (1 <= n <= 1000).
- The second line will contain n integers, representing the elements of the array.
Output the modified array in a single line, with elements separated by spaces.
Example:
Input:
5
1 2 3 4 5
Output:
2 1 4 3 5
Key concepts
arraysswappingmanipulation
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now