52. Reverse an Array In Place
Core1000 ms256 MBSolved by 0%
Print the array in reverse order, separated by single spaces, on one line.
Do it by swapping elements within the array rather than building a second one — that constraint is the point of the exercise.
Constraints - `1 ≤ n ≤ 100000` - `-1000000 ≤ a[i] ≤ 1000000`
Input
The first line contains an integer n.
The second line contains n space-separated integers.
Output
Print the reversed array on ONE line, separated by single spaces.
Input5
1 2 3 4 5
Output5 4 3 2 1
Notehas an odd length, so one element stays in the middle
Input4
1 2 3 4
Output4 3 2 1
Notehas an even length, so every element moves
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution