Skip to content
Onsite

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

Run checks the 3 visible tests, Submit all 8.