Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Reverse An Array

Easy Acceptance 85.00% Points 20.00

You are given an array of integers. Your task is to reverse the array using recursion only. You are not allowed to use any loops or built-in reverse functions.

Return the array after reversing all its elements.

Examples
Example 1

Example 1

Input: arr[] = [1 2 3 4 5]

Output: 5 4 3 2 1

Explanation: The order of the elements is reversed.

Example 2

Example 2

Input: arr[] = [10 20 30 40]

Output: 40 30 20 10

Explanation: The first element becomes last and the last becomes first.

Example 3

Example 3

Input: arr[] = [7]

Output: 7

Explanation: A single element remains the same after reversing.

Hints
Hint 1
N/A
Constraints
  • 1 <N<105
  • -109 < arr[i] < 109
Companies
Apple Coinbase Media.net
Topics
Recursion
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions