Two-Way Partition - aloalgo

Two-Way Partition

Easy

You are given an array numbers that contains only 0 and 1 values.

Your task is to sort the array numbers in-place such that all 0s appear before all 1s.

Do not return anything, instead modify the numbers input.

Example 1

Input
[1, 0, 1, 0, 0]
Output
[0, 0, 0, 1, 1]
Explanation:

The array contains elements 1, 0, 1, 0, 0. After sorting, all 0s come first, then 1s.

Example 2

Input
[1, 1, 0, 0]
Output
[0, 0, 1, 1]
Explanation:

The array contains elements 1, 1, 0, 0. After sorting, the 0s come first, then 1s.

Example 3

Input
[0, 0, 1, 1]
Output
[0, 0, 1, 1]
Explanation:

The array is already sorted, so its order remains unchanged.

Loading...
Input
[1, 0, 1, 0, 0]
Output
[0, 0, 0, 1, 1]

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!