Bootcamps
Masterclasses
Menu
Courses
Account
Login / Sign Up

Reverse An Array

Easy Acceptance 85% Points 20

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.

Constraints
  • 1 <N<105
  • -109 < arr[i] < 109
Topics
Recursion
Companies
Apple Coinbase Media.net
Added 19 Jul 2026 85% acceptance
Ln 1, Col 1Sign in to save your code
1 2 3 4 5
5 4 3 2 1