Mixed Sorting
Given a list of integers nums
, sort the array such that:
- All even numbers are sorted in increasing order
- All odd numbers are sorted in decreasing order
- The relative positions of the even and odd numbers remain the same
Constraints
n ≤ 100,000
wheren
is the length ofnums
https://binarysearch.com/problems/Mixed-Sorting
Examples
Example 1
Input
- nums =
[8, 13, 11, 90, -5, 4]
Output
- answer =
[4, 13, 11, 8, -5, 90]
Explanation
The even numbers are sorted in increasing order, the odd numbers are sorted in decreasing number, and the relative positions were [even, odd, odd, even, odd, even] and remain the same after sorting.
Leave a comment