C++ Solution || Easy to Understand || O(N) TIME and O(1) Space
Intuition\nThe problem seems to require calculating the number of steps to reach some goal. The idea is to iterate the string from the right end, counting the n
# Intuition\nThe problem seems to require calculating the number of steps to reach some goal. The idea is to iterate the string from the right end, counting the number of `\'0\'` encountered (these are the positions where `\'1\'` will be moved to). Whenever a `\'1\'` is found, we add the number of previously encountered `\'0\'` to the answer (since that represents the number of moves required to shift the `\'1\'` to the correct position).\n\n# Approach\n1. **We initialize two variables**:\n    - `cnt` to count the number of \'0\'s encountered from the right side of the string.\n    - `ans` to accumulate the number of swaps needed.\n    -  We iterate from the rightmost character (`r = n - 1`) to the leftmost character of the string.\n2.  **For each character**:\n    - If it\'s a `\'0\'`, we increment the cnt because this is where a `\'1\'` might be moved to.\n    - If it\'s a `\'1\'`, we add the current value of `cnt` to `ans` since the `\'1\'` will need to jump over all previous `\'0\'s` encountered.\n3. At the end of the loop, the `ans` variable holds the total number of swaps needed.\n\n\n# Complexity\n- Time complexity:. $$O(n)$$\n\n- Space complexity: $$O(1)$$ \n\n# Code\n```cpp []\nclass Solution {\npublic:\n    long long minimumSteps(string s) {\n        int n = s.length();\n        int r = n - 1;\n        long long cnt = 0;\n        long long ans = 0;\n        while (r >= 0) {\n            if (s[r] == \'0\') {\n                cnt++;\n            } else {\n                ans += cnt;\n            }\n            r--;\n        }\n        return ans;\n    }\n};\n```\n# *Quote of the day*\n\n> ***Challenges are what make life interesting; overcoming them is what makes life meaningful.***\n\n\n\n\n![1721315779911.jpeg](https://assets.leetcode.com/users/images/ddb52c46-979f-4d68-a218-ed33b242d5a6_1728985770.4957016.jpeg)\n\n\n
['String', 'Greedy', 'C++']