Solution Review: Rearrange Sorted Array in Max/Min Form
Explore how to rearrange a sorted array in max/min form using two C# solutions. Understand an approach with extra space and a space-optimized method that stores two elements at one index. Learn to implement these with O(n) time complexity for efficient coding.
We'll cover the following...
We'll cover the following...
Solution 1: Creating a new array
Explanation
In this solution, first create an empty array result whose size is equal to the size of the original array arr. Then start iterating over the array. Store the maximum number in the start of the array, then store the minimum number next to it, and so on. In the end, you should store the result array to the original array. Look at the example below:
Time complexity
The time complexity of this problem is ...