1702. Maximum Binary String After Change
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    string maximumBinaryString(string binary) {
        int n = binary.size();
        int idx = 0;
        
        while (idx < n && binary[idx] == '1') idx++;
        if (idx == n) return binary;

        int onesCount = 0;
        for (int i = idx; i < n; ++i) {
            if (binary[i] == '1') onesCount++;
        }

        for (int i = idx; i < n - onesCount - 1; ++i) binary[i] = '1';
        binary[n - onesCount - 1] = '0';
        for (int i = n - onesCount; i < n; ++i) binary[i] = '1';

        return binary;
    }
};

```
['C++']