Search
⌘K

Leetcode 2938. Separate Black and White Balls

Given a binary string, find the minimum number of adjacent swaps needed to move all 1s to the right (0s to the left); this equals the number of inversions (pairs where a '1' appears before a '0'), which can be computed in linear time for n up to 1e5.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Your account is free and you can post anonymously if you choose.