1
// Approach-1 (Using sorting O(nlogn))4
nums[i-1] < nums[i] > nums[i+1]7
So, just sort the input and choose wisely to satisfy above condition.11
sort it : [0, 2, 6, 7, 9]13
result : [0, _, 2, _, 6] - 1st loop (fill alternaltely)14
result : [0, 7, 2, 9, 6] - 2nd loop (fill next larger numbers from nums to15
result in spaces left)21
vector<int> rearrangeArray(vector<int> &nums) {23
sort(begin(nums), end(nums));25
vector<int> result(n);28
for (; i < n && j < n; i++, j += 2) // alternately fill so that you leave29
// one space in between for large number33
for (; i < n && j < n; i++,34
j += 2) // filter the large number in spaces between that we left above