SLIDING WINDOW SOLUTION || CPP
\n\n# 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\
\n\n# 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\n# Code\n```\nclass Solution {\npublic:\n    string shortestBeautifulSubstring(string s, int k) \n    {\n        string ans="";\n        int n = s.size();\n        int i = 0,j=0;\n        int temp = 0;\n        while(j<n)\n        {\n            if(s[j]==\'1\')\n            {\n                temp++;\n            }\n            if(temp>k)\n            {\n                while(i<j)\n                {\n                    if(s[i]==\'1\' && temp==k)\n                    {\n                        break;\n                    }\n                    if(s[i]==\'1\')\n                    {\n                        temp--;\n                    }\n                    i++;\n                }\n            }\n            if(temp==k)\n            {\n                while(1)\n                {\n                    if(s[i]==\'1\')\n                    {\n                        break;\n                    }\n                    i++;\n                }\n                if(ans.size()>=j-i+1 || ans=="")\n                {\n                    if(ans.size()==j-i+1)\n                    {\n                        ans = min(ans,s.substr(i,j-i+1));\n                    }\n                    else\n                    {\n                        ans = s.substr(i,j-i+1);\n                    }\n                }\n            }\n            j++;\n        }\n        return ans;\n    }\n};\n```
['Sliding Window', 'C++']