Free written solutionSeparate Black and White Balls (LeetCode 2938): Solution and Explanation
Given a binary string where 1 is a black ball and 0 is a white ball, return the fewest adjacent swaps needed to move every black ball to the right of every white ball.
Read the intuition, approach, code and complexity →