C solution
Result\n\n\n# Solution\nTo separate black (1) and white (0) balls with the minimum number of swaps, we use an inversion counting approach. As we iterate through
# Result\n![image.png](https://assets.leetcode.com/users/images/f05ae993-6fee-4014-816d-c95ab1fbb6a7_1728960288.0241928.png)\n\n# Solution\nTo separate black (`1`) and white (`0`) balls with the minimum number of swaps, we use an **inversion counting** approach. As we iterate through the string, whenever we encounter a `0`, we add the number of `1`s seen so far to the total swap count. This is because each of those `1`s would need to move past the current `0` to achieve the correct grouping. By the end of the traversal, the accumulated swap count gives the minimum number of adjacent swaps required to place all `0`s on the left and all `1`s on the right. This solution runs in **O(n)** time, making it efficient for large inputs.\n# Code\n```c []\n long long minimumSteps( char *s) {\n     long long count_ones = 0;     // Number of \'1\'s encountered so far\n     long long swap_count = 0;     // Total number of swaps needed\n\n    for (int i = 0; s[i] != \'\\0\'; i++) {\n        if (s[i] == \'1\') {\n            count_ones++;\n        } else if (s[i] == \'0\') {\n            swap_count += count_ones;\n        } \n    }\n\n    return swap_count;\n}\n```
['Two Pointers', 'C']