Your question is Sort Balls by Color. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Sort an array of balls that come in 2 colors so that same colors are grouped together.
Asked in the Round 1 (90 min) stage. This is a LeetCode-style Sort Colors variant. Reported follow-up: generalize to sort n balls of k colors.
Implement sort_two_colors(balls), where balls is a list containing only 0 and 1. Rearrange the list in place so all 0s appear before all 1s, and return the same list.
def sort_two_colors(balls):