Learner Level

Implement the reverseArrayCopy method that returns a new array with the input elements in reverse order.

The input contains an integer array nums and its length size. Your task is to return a new array containing the same values in reverse order.

Do not change the meaning of the values; only their order should be reversed. For example, [1,2,3,4] becomes [4,3,2,1].

Example 1
Input:
nums (int[]) = [1,2,3,4]
size (int) = 4
Return:
(int[]) [4,3,2,1]
Example 2
Input:
nums (int[]) = [9]
size (int) = 1
Return:
(int[]) [9]
Example 3
Input:
nums (int[]) = [-1,0,5]
size (int) = 3
Return:
(int[]) [5,0,-1]

Create a separate result array so the original order can be read safely while building the reversed copy.

Start from the last element of nums and place each value into the result array from left to right. When all values are copied, return the result.

Pseudocode:

function reverseArrayCopy(nums, size):
    result = empty array
    for i from size - 1 down to 0:
        add nums[i] to result
    return result
Run your code to see the result.