Tap here to switch tabs
Problem
Submissions

Problem: Separate Black and White Balls

Try to solve the Separate Black and White Balls problem.

Statement

You are given a $0$ indexed binary string s of length n, where '$1$' represents a black ball and '$0$' represents a white ball.

In each step, you may choose two adjacent balls and swap them.

Return the minimum number of steps required to group all the black balls to the right and all the white balls to the left.

Constraints:

  • 1≤1 \leq n == s.length ≤105\leq 10^5

  • s[i] is either '$0$' or '$1$'.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Separate Black and White Balls

Try to solve the Separate Black and White Balls problem.

Statement

You are given a $0$ indexed binary string s of length n, where '$1$' represents a black ball and '$0$' represents a white ball.

In each step, you may choose two adjacent balls and swap them.

Return the minimum number of steps required to group all the black balls to the right and all the white balls to the left.

Constraints:

  • 1≤1 \leq n == s.length ≤105\leq 10^5

  • s[i] is either '$0$' or '$1$'.