Given an array 'arr' of size 'n'.
Return an array with all the elements placed in reverse order.
You don’t need to print anything. Just implement the given function.
Example:
Input: n = 6, arr = [5, 7, 8, 1, 6, 3]
Output: [3, 6, 1, 8, 7, 5]
Explanation: After reversing the array, it looks like this [3, 6, 1, 8, 7, 5].
The first line contains an integer n, the size of the array
The second line contains n integers, the array.
Output format:
Return the reversed array.
8
3 1 1 7 4 2 6 11
11 6 2 4 7 1 1 3
After reversing the array, it looks like this [11, 6, 2, 4, 7, 1, 1, 3].
4
8 1 3 2
2 3 1 8
After reversing the array, it looks like this [2, 3, 1, 8].
The expected time complexity is O(n).
1 <= 'n' <= 10^6
-10^9 <= 'arr[i]' <=10^9
Use an extra array.
Approach:
Algorithm:
O(n), Where n is the size of the array
We are iterating through the array once.
Hence the time complexity would be O(n).
O(n) where n is the size of the array
Since we are creating a new array of size n.
Hence the space complexity would be O(n).