beats 100% || one pass || explained
Intuition\n Describe your first thoughts on how to solve this problem. \nCount swap needed to put 0 before all 1\'s.\n\n# Approach\n Describe your approach to s
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nCount swap needed to put 0 before all 1\'s.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\nThe idea is to count the number of white balls encountered so far while iterating through the string.\n\nFor each black ball encountered, add the count of white balls to the total steps, as these are the steps needed to move the black ball to the right of the white balls.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n    O(N)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n    O(1)\n\n# Code\n```\nclass Solution {\npublic:\n    #define ll long long\n    ll solve(string &s) {\n        ll n = s.length();\n        long long whiteCount = 0; // Number of white balls encountered so far\n        long long steps = 0;     // Total number of steps\n\n        // Iterate through the string\n        for (int i = 0; i < n; ++i) {\n            if (s[i] == \'0\') {\n                // If the current ball is black, add the number of white balls encountered so far to the total steps\n                steps += whiteCount;\n            } else {\n                // If the current ball is white, increment the count of white balls encountered so far\n                whiteCount++;\n            }\n        }\n\n        return\xA0steps;\n\n    }\n    \n    long long minimumSteps(string s) {\n        \n        ll cnt=solve(s);\n        return cnt;\n        \n        \n    }\n};\n```
['String', 'C++']