Reverse an Array (Set 12)

Easy

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

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

Example 1

reverseArrayValues()
Input
nums = [5, 39, 35, -3, -5, 15, 7, -13, 26, 38, -14, -10, -26, -6, 27, -15, 25, 10, -28, -11, 17, -19, 10, -20, -7, -12, 31, 7, -2, -40, -26, -2, -28, 32, -37, -15, -29, 6, 7, 29, 9, 36, -21, 2, 30, -30]
Output
[-30, 30, 2, -21, 36, 9, 29, 7, 6, -29, -15, -37, 32, -28, -2, -26, -40, -2, 7, 31, -12, -7, -20, 10, -19, 17, -11, -28, 10, 25, -15, 27, -6, -26, -10, -14, 38, 26, -13, 7, 15, -5, -3, 35, 39, 5]

Why

`reverseArrayValues` returns `[-30, 30, 2, -21, 36, 9, 29, 7, 6, -29, -15, -37, 32, -28, -2, -26, -40, -2, 7, 31, -12, -7, -20, 10, -19, 17, -11, -28, 10, 25, -15, 27, -6, -26, -10, -14, 38, 26, -13, 7, 15, -5, -3, 35, 39, 5]` for this input.

Example 2

reverseArrayValues()
Input
nums = [8, -15, -34, 22, -25, 1, 40, 17, 7, -15, 20, 33, -9, -40, 19, -36, -18, -33, 34, -22, -10, -20, 8, 24, 29, 0, -24, 9, 14, 30, -9, 16, 6, 11, 22, -7, -38, -30, -40, 17, 2, -25, 0, 17, 29, -27, 21, 34]
Output
[34, 21, -27, 29, 17, 0, -25, 2, 17, -40, -30, -38, -7, 22, 11, 6, 16, -9, 30, 14, 9, -24, 0, 29, 24, 8, -20, -10, -22, 34, -33, -18, -36, 19, -40, -9, 33, 20, -15, 7, 17, 40, 1, -25, 22, -34, -15, 8]

Why

`reverseArrayValues` returns `[34, 21, -27, 29, 17, 0, -25, 2, 17, -40, -30, -38, -7, 22, 11, 6, 16, -9, 30, 14, 9, -24, 0, 29, 24, 8, -20, -10, -22, 34, -33, -18, -36, 19, -40, -9, 33, 20, -15, 7, 17, 40, 1, -25, 22, -34, -15, 8]` 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.