Ctrl K

Zeros Before Ones

Easy
You are given an array of positive integers numbers. Replace every even number with 0 and every odd number with 1. Then sort the resulting array in non-decreasing order and return it. In other words, the answer starts with one zero for each even number, followed by one 1 for each odd number.
Example 1
numbers=[7, 12, 9, 30, 5] → [0, 0, 1, 1, 1]

The even numbers 12 and 30 become 0, the odd 7, 9 and 5 become 1. That gives [1, 0, 1, 0, 1], which sorts into [0, 0, 1, 1, 1].

Example 2
numbers=[8, 2, 6] → [0, 0, 0]

Every number is even, so only zeros remain.

Constraints
  • 1 ≤ len(numbers) ≤ 100
  • 1 ≤ numbers[i] ≤ 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Candidate With Most Votes EasyValues One Apart EasyOrder by Set Bits EasyNeither the Lowest nor the Highest EasyPresent in Every List Easy
loading Python…
Input
numbers=[7, 12, 9, 30, 5]
Expected
[0, 0, 1, 1, 1]

Run checks the first 3 tests in your browser. Submit checks all 94 tests on the server, hidden ones included.