BackeasyArrays

Reverse the Lineup Solution

Problem Statement

You are managing a warehouse inventory system. Due to a sudden change in shipping priority, you need to reverse the order of items in a list. Write a function `reverseArray(vector<int>& arr)` that reverses the given array of integers **in-place** (without allocating extra space for another array). ### Input Format - A vector of integers `arr`. ### Output Format - The function should modify `arr` in-place. ### Constraints - `1 <= arr.size() <= 10^5` - `-10^9 <= arr[i] <= 10^9`

Example 1
Input
[1, 2, 3, 4, 5]
Output
[5, 4, 3, 2, 1]

Explanation: Reversing [1, 2, 3, 4, 5] gives [5, 4, 3, 2, 1].

Example 2
Input
[10, 20]
Output
[20, 10]

Explanation: Reversing [10, 20] gives [20, 10].

Constraints

  • 1 <= arr.size() <= 10^5
  • -10^9 <= arr[i] <= 10^9
Live Compiler
Sign InSign Up
Loading...
Test Cases & Output
Click "Run" to execute