Reverse an Array (Set 14)

Easy

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

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

Example 1

reverseArrayValues()
Input
nums = [9, 27, 2, -9, -21, -35, 20, 5, -22, 31, 23, -24, 4, 4, 35, -37, -40, 33, -27, 20, -30, -30, 13, 27, 27, 9, -26, -10, -10, -37, 11, 24, -27, 23, 30, 38, 32, 23, -6, -18, -21, 11, 29, 31, 6, 19, 33, 32]
Output
[32, 33, 19, 6, 31, 29, 11, -21, -18, -6, 23, 32, 38, 30, 23, -27, 24, 11, -37, -10, -10, -26, 9, 27, 27, 13, -30, -30, 20, -27, 33, -40, -37, 35, 4, 4, -24, 23, 31, -22, 5, 20, -35, -21, -9, 2, 27, 9]

Why

`reverseArrayValues` returns `[32, 33, 19, 6, 31, 29, 11, -21, -18, -6, 23, 32, 38, 30, 23, -27, 24, 11, -37, -10, -10, -26, 9, 27, 27, 13, -30, -30, 20, -27, 33, -40, -37, 35, 4, 4, -24, 23, 31, -22, 5, 20, -35, -21, -9, 2, 27, 9]` for this input.

Example 2

reverseArrayValues()
Input
nums = [-28, -27, 30, 35, 26, 18, 0, -25, 40, 4, 0, -40, -30, -22, -13, 2, -32, 18, -21, -21, 13, 7, 15, -26, 0, -16, 15, -10, 12, -17, -2, -40, 27, 40, 12, -10, 16, -15, 24, 26, 6, -24, -28, -40, -18, 37, 12, -37]
Output
[-37, 12, 37, -18, -40, -28, -24, 6, 26, 24, -15, 16, -10, 12, 40, 27, -40, -2, -17, 12, -10, 15, -16, 0, -26, 15, 7, 13, -21, -21, 18, -32, 2, -13, -22, -30, -40, 0, 4, 40, -25, 0, 18, 26, 35, 30, -27, -28]

Why

`reverseArrayValues` returns `[-37, 12, 37, -18, -40, -28, -24, 6, 26, 24, -15, 16, -10, 12, 40, 27, -40, -2, -17, 12, -10, 15, -16, 0, -26, 15, 7, 13, -21, -21, 18, -32, 2, -13, -22, -30, -40, 0, 4, 40, -25, 0, 18, 26, 35, 30, -27, -28]` 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.