Input: N = 1, X[] = {1, 2}
Output: X[] = {2, 1}, Median = 2
Explanation: Y[] = { max(X[1], X[2]) }, Y[] = {2}.
Median of Y[] = 2, 2 is the maximum possible value of median that can achieve by arrange elements of X[].
Input: N = 3, X[] = {1, 2, 3, 4, 5, 6}
Output: X[] = {3, 1, 2, 5, 6, 4}, Median = 5
Explanation: Y[] = { max(3, 1), max(2, 5), max(6, 4) }, Y[] = {3, 5, 6}.
Median of Y[] = 5, 5 is the maximum possible value of median that can achieve by arrange elements of X[].
Consider N = 3, X[] = {1, 2, 3, 4, 5, 6}
After sorting X[] will be: {1, 2, 3, 4, 5, 6}. Let the new Arrangement: {A1, A2, A3, A4, A5, A6}
- Put left half X[] = {1, 2, 3} on odd indices of new Arrangement, Then Arrangement: {1, A2, 2, A4, 3, A6}
- Put right half X[] = {4, 5, 6} on even indices of new Arrangement. Then, Arrangement: {1, 4, 2, 5, 3, 6}
Now, It can be verified that Y[] will be = {4, 5, 6}, 5 is maximum possible median and value 5 is at middle of right half of X[] = {4, 5, 6}
Below is the implementation of the approach.