Approach using sliding window in O(N^2) time and O(N) space complexity.
Intuition\nTo find string containing only k number of \'1\' in string use sliding window\n\n# Approach\nhere, ans is string to return.\nfor loop starting from 0
# Intuition\nTo find string containing only `k` number of `\'1\'` in string use sliding window\n\n# Approach\nhere, `ans` is string to return.\nfor loop starting from 0 to n-1:\nand controle the len of temp string `str` using `j` which is depend up on number of `\'1\'` in `str`.\nCompare `lexicographically`  using `min(ans,str)`\n\nfinally return `ans`.\n\n# Complexity\n- Time complexity:\n$$O(N^2) $$\n\n- Space complexity:\n$$O(N)$$\n\n# Code\n```\nclass Solution {\npublic:\n    string shortestBeautifulSubstring(string s, int k) {\n        int n = s.size();\n        int j=0;\n        int c=0;\n        string ans = "";\n        for(int i=0;i<n; i++){\n            if(s[i]==\'1\') c++;\n            while(j<=i && c==k){\n                string str = s.substr(j,i-j+1);\n                if(ans.size()==0 || str.size()<ans.size()){\n                    ans = str;\n                } else if(ans.size()== str.size()){\n                    ans = min(ans,str);\n                }\n                if(s[j]==\'1\') c--;\n                j++;\n            }\n        }\n        return ans;\n    }\n};\n```
['String', 'Sliding Window', 'C++']