Reverse an array

Beginner Problems Basic Recursion Easy
  • Fun Fact: The concept of reversing an array is used in many popular applications like social media platforms or music streaming apps
  • For instance, in apps like Instagram or Facebook, when you scroll through comments or posts, you're actually traversing a reversed array
  • The latest posts/comments are at the beginning of the array and as you scroll, you move towards the older posts/comments at the end of the array
  • Similarly, in a music app's playlist, the 'play in reverse order' functionality also uses this concept
  • Also, reversing is a commonly used feature in data visualization, where one might want to flip the data to view it from a different perspective

Given an array nums of n integers, return reverse of the array.

Examples:

Input : nums = [1, 2, 3, 4, 5]

Output : [5, 4, 3, 2, 1]

Input : nums = [1, 3, 3, 3, 5]

Output : [5, 3, 3, 3, 1]

Input : nums = [1, 2, 1]

Constraints

  • 1 <= n <= 100
  • 1 <= nums[i] <= 100

Company Tags

TCS Cognizant Accenture Infosys Capgemini Wipro IBM HCL Tech Mahindra MindTree