Input: N = 3, arr[] = {1, 3, 5}
Output: {5, 3, 1}
Explanation: The sequence of operation is [1, 3, 5] -> [1, 5, 3] -> [5, 1, 3] -> [5, 3, 1].
Input: N = 4, arr[] ={ 1, 3, 4, 2}
Output: {3, 1, 4, 2}
Explanation: [1, 3, 4, 2], [1, 3, 2, 4], [3, 1, 2, 4] and [3, 1, 4, 2] are all possible values of the final array among which the last one is the lexicographically largest.
Separate the segments on the basis of same parity and as in same parity segments we can do any number of swaps so sorting it in decreasing order will give us the lexicographically largest array.
Aso we know that the summation of two even numbers = even, sum of two odd numbers = even and sum of one odd and one even is odd, that's why we are separating the segments on the basis of same parity.