933. Rearrange Array in Increasing-Decreasing Order

Given an array nums of integers, rearrange the elements such that:

  • The first half of the array is in strictly increasing order.
  • The of the array is in strictly decreasing order.

You need to modify the array in-place and return the rearranged array.

Example 1:

Input: arr = [10, 20, 30, 40]

Output: [10, 20, 40, 30]

Explanation: 

  • First half: [10, 20] → sorted ascending: [10, 20]
  • Second half: [30, 40] → sorted descending: [40, 30]
  • Result: [10, 20, 40, 30]

Example 2:

Input: arr = [5, 4, 6, 2, 3, 8, 9, 7]

Output: [2, 4, 5, 6, 9, 8, 7, 3]

Explanation:

  • First half: [5, 4, 6, 2] → sorted ascending: [2, 4, 5, 6]
  • Second half: [3, 8, 9, 7] → sorted descending: [9, 8, 7, 3]
  • Result: [2, 4, 5, 6, 9, 8, 7, 3]

Now Your Turn!

Pick the correct output for the given input

Input: arr = [100, 50, 25, 75, 90, 10, 60, 80]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 2 <= arr.length <= 105
  • arr.length is even
  • 1 <= arr[i] <= 106
0
class Solution {
public:
vector<int> rearrangeArray(vector<int>& arr) {
// Your code goes here
}
};
Test Case

Input:

Arr