Reverse an Array (Set 6)

Easy

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

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

Example 1

reverseArrayValues()
Input
nums = [23, 33, -28, 35, 28, -26, 16, -32, -34, -38, -37, 24, -32, 7, -30, 1, 17, 1, -19, -2, -40, 18, 29, -13, 19, -6, 9, -27, 33, -38, -29, -28, -16, -25, -33, -19, 40, -35, -6, -30, 7, -18, -20]
Output
[-20, -18, 7, -30, -6, -35, 40, -19, -33, -25, -16, -28, -29, -38, 33, -27, 9, -6, 19, -13, 29, 18, -40, -2, -19, 1, 17, 1, -30, 7, -32, 24, -37, -38, -34, -32, 16, -26, 28, 35, -28, 33, 23]

Why

`reverseArrayValues` returns `[-20, -18, 7, -30, -6, -35, 40, -19, -33, -25, -16, -28, -29, -38, 33, -27, 9, -6, 19, -13, 29, 18, -40, -2, -19, 1, 17, 1, -30, 7, -32, 24, -37, -38, -34, -32, 16, -26, 28, 35, -28, 33, 23]` for this input.

Example 2

reverseArrayValues()
Input
nums = [23, -31, -32, -23, 10, -40, -28, 6, -32, 22, -18, -31, -11, 39, 3, -12, -22, -22, 26, 6, -29, -5, 36, 7, -11, 17, -23, 39, -19, -13, 24, 8, -9, 11, 5, -23, 21, -22, -31, -21, 0]
Output
[0, -21, -31, -22, 21, -23, 5, 11, -9, 8, 24, -13, -19, 39, -23, 17, -11, 7, 36, -5, -29, 6, 26, -22, -22, -12, 3, 39, -11, -31, -18, 22, -32, 6, -28, -40, 10, -23, -32, -31, 23]

Why

`reverseArrayValues` returns `[0, -21, -31, -22, 21, -23, 5, 11, -9, 8, 24, -13, -19, 39, -23, 17, -11, 7, 36, -5, -29, 6, 26, -22, -22, -12, 3, 39, -11, -31, -18, 22, -32, 6, -28, -40, 10, -23, -32, -31, 23]` 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.