Beats 100%
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 shortestBeautifulSubstring(string s, int k) {
        int n = s.size();

        int i = 0;
        int left = 0;
        int count = 0;
        string ans;

        while (i < n) {
            if (s[i] == '1')
                count++;

            while (count > k) {
                if (s[left] == '1')
                    count--;
                left++;
            }

            while (count == k) {
                string t = s.substr(left, i - left + 1);

                if (ans.empty() || i - left + 1 < ans.size()) {
                    ans = t;
                } else if (i - left + 1 == ans.size() && t < ans) {
                    ans = t;
                }

                if (s[left] == '1')
                    count--;
                left++;
            }

            i++;
        }

        return ans;
    }
};
```
['Sliding Window', 'C++']