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.
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
Input: arr[] = [10 20 30 40]
Output: 40 30 20 10
Explanation: The first element becomes last and the last becomes first.
Example 3
Input: arr[] = [7]
Output: 7
Explanation: A single element remains the same after reversing.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
1 2 3 4 5
5 4 3 2 1
7 14 21 28
25 21 14 7
100 200 300
300 200 100