Reverse an array

Beginner Problems Basic Arrays Easy
  • In many popular software applications such as video editors or music players, reversing an array, which is essentially reversing a sequence, is an important feature
  • For example, reversing a video clip plays the frames in backward order leading to a reversed video, which is achieved through the same underlying concept as reversing an array

Given an array arr of n elements. The task is to reverse the given array. The reversal of array should be inplace.

Examples:

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]

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].

Input: n=3, arr = [1,2,1]

Constraints

1 <= n <= 104

1 <= arr[i] <= 105

Company Tags

TCS Cognizant Accenture Infosys Capgemini Wipro IBM HCL Tech Mahindra MindTree