Reverse an Array (Set 13)

Easy

Given an array of integers nums, return a new array with the same values in reverse order.

Reverse an Array (Set 13) — the data. This set runs 4 cases: nums holds arrays of 48–48 items, with values from -38 to 40. The hidden cases are the largest of the set.

Example 1

reverseArrayValues()
Input
nums = [-2, -38, 14, -29, 5, -36, 6, -30, -5, 33, -17, -2, 2, 26, -36, -26, -4, 5, 34, -22, -27, -21, 5, -32, 17, 40, 11, 37, -34, -27, 21, -35, 18, -38, -22, 23, -14, -31, 26, -24, -32, -2, 17, -8, -25, 21, -29, 13]
Output
[13, -29, 21, -25, -8, 17, -2, -32, -24, 26, -31, -14, 23, -22, -38, 18, -35, 21, -27, -34, 37, 11, 40, 17, -32, 5, -21, -27, -22, 34, 5, -4, -26, -36, 26, 2, -2, -17, 33, -5, -30, 6, -36, 5, -29, 14, -38, -2]

Why

`reverseArrayValues` returns `[13, -29, 21, -25, -8, 17, -2, -32, -24, 26, -31, -14, 23, -22, -38, 18, -35, 21, -27, -34, 37, 11, 40, 17, -32, 5, -21, -27, -22, 34, 5, -4, -26, -36, 26, 2, -2, -17, 33, -5, -30, 6, -36, 5, -29, 14, -38, -2]` for this input.

Example 2

reverseArrayValues()
Input
nums = [-19, -36, 6, 37, 34, 40, -35, 21, 19, -38, 30, 35, 28, 20, -16, 27, -18, 16, -18, 14, 26, 36, 18, 13, 19, 14, -35, -37, 31, -7, 18, -32, -23, 38, -28, -31, -34, -11, -29, -10, -28, 6, 0, 6, 8, 20, -8, -27]
Output
[-27, -8, 20, 8, 6, 0, 6, -28, -10, -29, -11, -34, -31, -28, 38, -23, -32, 18, -7, 31, -37, -35, 14, 19, 13, 18, 36, 26, 14, -18, 16, -18, 27, -16, 20, 28, 35, 30, -38, 19, 21, -35, 40, 34, 37, 6, -36, -19]

Why

`reverseArrayValues` returns `[-27, -8, 20, 8, 6, 0, 6, -28, -10, -29, -11, -34, -31, -28, 38, -23, -32, 18, -7, 31, -37, -35, 14, 19, 13, 18, 36, 26, 14, -18, 16, -18, 27, -16, 20, 28, 35, 30, -38, 19, 21, -35, 40, 34, 37, 6, -36, -19]` for this input.
Constraints
0 <= nums.length <= 10^5
-10^4 <= nums[i] <= 10^4
Every case in this set must pass: the first two are visible on Run, the last two unlock on Submit.

Topics

ArraysTwo Pointers

Implement reverseArrayValues in the editor and return the answer — printing it is never graded.