100% || C++
Intuition
Check unitl you find the exact number of ones
if ffound, then compare the string with most recent string and cut the string from beginning (increment
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
- Check unitl you find the exact number of ones
- if ffound, then compare the string with most recent string and cut the string from beginning (increment the value of i)

# 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();
        string ans;
        int i=0;
        int j=0;
        int c=0;
        while(j<n){
            if(s[j]=='1') c++;
            if(c==k){
                while(i<n && c==k){
                    string s1=s.substr(i,j-i+1);
                    if(ans.size()==0 || s1.size()<ans.size()){
                        ans=s1;
                    }
                    else if(s1.size()==ans.size()){
                        ans=min(ans,s1);
                    }
                    if(s[i]=='1') c--;
                    i++;
                }
            }
            j++;
        }
        return ans;
    }
};

```
['C++']