85. Reverse an Array With Two Pointers
Core1000 ms256 MBSolved by 0%
Read n and then n integers, and print them reversed, separated by
single spaces.
The exercise is to use two pointers — one starting at the front and one at the back — moving toward each other and swapping as they go, rather than building a second array.
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 the middle element stays put
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