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
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.