Transform Array by Parity

You are given an integer array nums. Transform nums by performing the following operations in the exact order specified:

  • Replace each even number with 0.
  • Replace each odd number with 1.
  • Sort the modified array in non-decreasing order.

Return the resulting array after performing these operations.

Example 1
Inputnums = [4,3,2,1]
Output[0,0,1,1]
Even numbers 4 and 2 become 0, odd numbers 3 and 1 become 1, and sorting gives [0, 0, 1, 1].
Example 2
Inputnums = [1,5,1,4,2]
Output[0,0,1,1,1]
Even numbers 4 and 2 become 0, odd numbers 1, 5, and 1 become 1, and sorting gives [0, 0, 1, 1, 1].

Constraints

  • 1 <= nums.length <= 100
  • 1 <= nums[i] <= 1000

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate