<p>There are <code>n</code> balls on a table, each ball has a color black or white.</p>

<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code>, where <code>1</code> and <code>0</code> represent black and white balls, respectively.</p>

<p>In each step, you can choose two adjacent balls and swap them.</p>

<p>Return <em>the <strong>minimum</strong> number of steps to group all the black balls to the right and all the white balls to the left</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;101&quot;
<strong>Output:</strong> 1
<strong>Explanation:</strong> We can group all the black balls to the right in the following way:
- Swap s[0] and s[1], s = &quot;011&quot;.
Initially, 1s are not grouped together, requiring at least 1 step to group them to the right.</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;100&quot;
<strong>Output:</strong> 2
<strong>Explanation:</strong> We can group all the black balls to the right in the following way:
- Swap s[0] and s[1], s = &quot;010&quot;.
- Swap s[1] and s[2], s = &quot;001&quot;.
It can be proven that the minimum number of steps needed is 2.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;0111&quot;
<strong>Output:</strong> 0
<strong>Explanation:</strong> All the black balls are already grouped to the right.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= n == s.length &lt;= 10<sup>5</sup></code></li>
	<li><code>s[i]</code> is either <code>&#39;0&#39;</code> or <code>&#39;1&#39;</code>.</li>
</ul>

# so it's like one of the strategies of counting the passes from the left and then counting the passes to the right and taking the min
# in this case, we count the swaps from the 0 white and count the swaps from the 1 black and see which one is the fewer steps
# not sure if we can just do one pass to know if it's fewer 0's or fewer 1's since we also have to know how far they are from the left/right edge
# so 2 passes and counting the swaps is just taking the index of the next position where the 1 to the right or 0 to the left should go
# minus the current index distance, and swapping for 0, we have a pointer from left to right, while swapping for 1, we have pointer right to left
class Solution:
  def minimumSteps(self, s: str) -> int:
    # left to right 0 white pass
    left_pass = list(s)
    l = r = 0
    left_steps = 0
    while r < len(left_pass):
      if left_pass[r] == "0":  # swap left if 0 found to the right of left
        left_steps += (r - l)
        left_pass[r], left_pass[l] = left_pass[l], left_pass[r]
        l += 1
      r += 1
    right_steps = float('INF')
    # # right to left 1 black pass
    # right_pass = list(s)
    # l = r = len(s)-1
    # right_steps = 0
    # while l >= 0:
    #   if right_pass[l] == "1":  # swap right if 1 found to the left of right
    #     right_steps += (r - l)
    #     right_pass[r], right_pass[l] = right_pass[l], right_pass[r]
    #     r -= 1
    #   l -= 1

    # return the min of left and right steps
    return min(left_steps, right_steps)
145