1 minute read

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 where n is the length of nums

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.

Solution

Leave a comment