FastPrepReverse an Array Iteratively
Problem · Array

Reverse an Array Iteratively

Learn this problem
EasyAmazon logoAmazonNEW GRADPHONE SCREEN
See Amazon hiring insights

Problem statement

Given an integer array nums, reverse its element order using an iterative algorithm and return the reversed array.

Do not use recursion or a library reversal operation.

Function

reverseArray(nums: int[]) → int[]

Examples

Example 1

nums = [1,2,3]return = [3,2,1]

The first and last values exchange positions while the middle value stays in place.

Example 2

nums = []return = []

Reversing an empty array produces an empty array.

Example 3

nums = [-1,0,5,5]return = [5,5,0,-1]

Values, including duplicates, appear in the opposite positional order.

Constraints

  • 0 <= nums.length <= 2 * 10^5.
  • -10^9 <= nums[i] <= 10^9.

More Amazon problems

drafts saved locally
public int[] reverseArray(int[] nums) {
  // write your code here
}
nums[1,2,3]
expected[3,2,1]
checking account