C++ || Greedy Solution🔥🔥|| O(n) time and O(1) space
Intuition\nFirst thought with this question is that if we group either the 0s or 1s together, then the other automatically gets grouped.\n Describe your first t
# Intuition\nFirst thought with this question is that if we group either the 0s or 1s together, then the other automatically gets grouped.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nWe iterate through the vector keeping track of the number of 0s that appear and the number of steps it will take to get them to the right end of the vector. Now adding the number of steps it will take to get every 0 to the rightmost position it get(basically to the position of the rightmost 1) we get the answer.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n) -> for iterating through the vector\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1) -> only constant space used\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    long long minimumSteps(string s) {\n        long long w = 0;\n        long long steps = 0;\n        int n = s.size();\n        for(int i=0;i<n;i++){\n            if(s[i]==\'0\'){\n                steps += i-w;\n                w++;\n            }\n        }\n        return steps;\n    }\n};\n```
['String', 'Greedy', 'C++']