Reverse an Array - III
You are given an integer array nums of size N. Reverse the array in place using recursion.
Do not create and return another array. Modify the provided array so that the first element becomes the last, the second becomes the second-last, and so on.
Note:
A normal iterative solution will pass the test cases, but the goal of this problem is to solve it using recursion and strengthen your understanding of recursive calls and base cases.
Example 1:
Input: nums = [1, 2, 3, 4, 5]
Output: [5, 4, 3, 2, 1]
Explanation: The elements are swapped recursively from the two ends toward the center.
Example 2:
Input: nums = [-3, 0, 7, 2]
Output: [2, 7, 0, -3]
Explanation: Reversing the order places the final element first and the first element last.
Now Your Turn!
Pick the correct output for the given inputInput: nums = [6, 1, 9]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= nums.length <= 100
- -104 <= nums[i] <= 104