Reverse an array
Given an array arr of n elements. The task is to reverse the given array. The reversal of array should be inplace.
Example 1:
Input: n=5, arr = [1,2,3,4,5]
Output: [5,4,3,2,1]
Explanation: The reverse of the array [1,2,3,4,5] is [5,4,3,2,1]
Example 2:
Input:Â n=6, arr = [1,2,1,1,5,1]
Output: [1,5,1,1,2,1]
Explanation: The reverse of the array [1,2,1,1,5,1] is [1,5,1,1,2,1].
Now Your Turn!
Pick the correct output for the given inputInput:Â n=3, arr = [1,2,1]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
1 <= n <= 104
1 <= arr[i] <= 105