Reverse an Array
EasyP2Coding
Return a new array with the elements of arr in reverse order. Use recursion; do not call a built-in reverse.
The input array should not be modified.
Example 1
- Input
- arr = [1,2,3,4,5]
- Output
- [5,4,3,2,1]
Example 2
- Input
- arr = [10,20]
- Output
- [20,10]
Example 3
- Input
- arr = []
- Output
- []
Constraints
- 0 <= arr.length <= 500
- -10^9 <= arr[i] <= 10^9
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 8. ⌘Enter runs, ⌘⇧Enter submits.