Simple py,JAVA code explained
1.Intuition(Brute Force)\n- My first thought is to simulate the problem as per question.\n- This uses two loops and TC is O(n^2)\n-   But TLE.So let\'s think in
# 1.Intuition(Brute Force)\n- My first thought is to simulate the problem as per question.\n- This uses two loops and TC is $$O(n^2)$$\n-   But **TLE**.So let\'s think in different approach.\n\n# Approach\n- Brute Force or simulation as per the question.\n1. the loop should break when first pos of ```\'1\'``` is greater than last pos of ```\'0\'```\n2. if ```\'0\'``` then pass\n3. else swap ```\'1\'``` with adjacent zero on right side as per question and ```break``` inner loop\n4. Increase ```count```\n\n# Complexity\n- Time complexity:\n$$O(n^2)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```python3 []\nclass Solution:                                  #Black-1 , White-0......Black to right and white to left!\n    def minimumSteps(self, s: str) -> int:\n        if \'1\' not in s:\n            return 0\n        if \'0\' not in s:\n            return 0\n        count=0\n        s=list(s)\n        while s.index(\'1\')<len(s)-1-s[::-1].index(\'0\'):\n            for i in range(len(s)-1,-1,-1):\n                if s[i]==\'0\':\n                    pass\n                else:\n                    if i!=len(s)-1 and s[i+1]==\'0\':\n                        s[i]=\'0\'\n                        s[i+1]=\'1\'\n                        break\n            #print(s)\n            count+=1\n        return count\n        \n        \n```\n\n---\n\n# 2.Intuition(Greedy)\n- Lets analayse and think about the question.\n- we need to make count the no swaps made by ```1``` to move to right across the ```0``` present in between the *current* ```1``` and *last*   ```1```.\n- Thus let\'s count the no of ```0``` across which our each ```1``` should be moved.\n\n# Hint:\n- Iterate right to left and count the number of 0 that have already occurred, whenever you iterate on 1 add that counter to the answer.\n\n# Approach\n- Greedy and counter.\n1. ```prev_no_of_zeroes``` counts the previous zeroes encountered so far,which helps to calculate ```count``` when ```1``` is encountered.\n2. ```count``` calculates min no of swaps.\n3. Iterate through string  from *right to left*.\n4. if ```0``` increase ```prev_no_of_zeroes```\n5. if ```1``` add the current previous no of zeroes to the ```count```\n \n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n\n```python3 []\nclass Solution:                                  #Black-1 , White-0......Black to right and white to left!\n    def minimumSteps(self, s: str) -> int:\n        if \'1\' not in s or \'0\' not in s:\n            return 0\n        count=0\n        prev_no_of_zeroes=0\n        for i in range(len(s)-1,-1,-1):\n            if s[i]==\'1\':\n                count+=prev_no_of_zeroes\n            elif s[i]==\'0\':\n                prev_no_of_zeroes+=1\n        return count\n        \n\n```\n```Java []\nclass Solution {\n    public long minimumSteps(String s) {\n        long count=0,prev_no_of_zeroes=0;\n        for(int i=s.length()-1;i>=0;i--){\n            if(s.charAt(i)==\'0\'){\n                prev_no_of_zeroes++;\n            }\n            else{\n                count+=prev_no_of_zeroes;\n            }\n        }\n        return count;\n    }\n}\n```\n\n
['Java', 'Python3']