Sliding Window | Easy | Beats 100% Memory | C++
# Complexity\n- Time complexity:O(N)\n<!-- Add your time complexity here, e.g. O(n)  \n\n \n\n# Code\n\nclass Solution {\npublic:\n    string shortestBeautifulS
<!--# Complexity\n- Time complexity:$$O(N)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n <!-- Space complexity:$$O(1)$$ -->\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n# Code\n```\nclass Solution {\npublic:\n    string shortestBeautifulSubstring(string s, int k) {\n        int i=0,j=0,count=0,n=s.size(),mini=INT_MAX;\n        string minAns="";\n        while(j<n){\n            if(s[j]==\'1\')count++;\n            while(s[i]==\'0\' || count>k){\n                if(s[i]==\'1\')count--;\n                i++;\n            }\n            if(count==k){                \n                int m=j-i+1;\n                string temp=s.substr(i,m);\n                if(m<mini){\n                    mini=m;\n                    minAns=temp;\n                }\n                else if(mini==m){//if they are same length take lexicographically smaller one\n                    if(minAns>temp){\n                        minAns=temp;\n                    }\n                }\n            }\n            j++;\n        }\n        return minAns;\n    }\n};\n```
['C++']