Optimized Java solution in 6 lines Beats 100.00%
Intuition
The problem likely involves counting the number of swaps or shifts required to move all '0' characters to the right while maintaining relative order.
**Intuition**
The problem likely involves counting the number of swaps or shifts required to move all '0' characters to the right while maintaining relative order. The key observation is that every '1' encountered will need to swap with all '0' characters to its right to achieve the desired order.

**Approach**
Traverse the string from right to left:

This helps in efficiently tracking how many '0' characters exist on the right of the current character.
Use a counter c to keep track of the number of '0' characters encountered:

Whenever a '0' is found, increment c.
When a '1' is encountered, add c to the answer (ans):

This means that each '1' contributes to c swaps since it needs to be moved past all '0' characters found so far.
Return the total swap count (ans).

**Complexity Analysis**
Time Complexity:
The solution traverses the string once from right to left, which takes O(n) time.
Space Complexity:
Only a few integer variables (ans and c) are used, making it O(1) space.

```java []
class Solution {
    public long minimumSteps(String s) {
        long ans = 0,c=0;
        for(int i=s.length()-1;i>=0;i--){
            if(s.charAt(i)=='0'){
                c++;
            }else{
                ans+=c;
            }
        }
        return ans;
    }
}
```






['Two Pointers', 'Java']