Simple Sliding Window
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    string shortestBeautifulSubstring(string s, int k) {\n\n        string ans = "";\n\n        int l=0;\n        int c1 = 0;\n\n        for(int r=0;r<s.size();r++){\n            c1 += (s[r] == \'1\');\n\n            while(c1 > k || (c1 == k && s[l] == \'0\')){\n                c1 -= (s[l] == \'1\');\n                l++;\n            }\n\n            if(c1 == k){\n                if(ans == "" || ans.size() > (r-l+1) || (ans.size() == (r-l+1) && ans > s.substr(l,r-l+1))){\n                ans = s.substr(l,r-l+1);\n            }\n            }\n        }\n\n        return ans;\n    }\n};\n```
['C++']