✅ CPP | Beats 100% | Sliding window
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nWe increment the right pointer until we get requried \'1\'s.\nOnce we get
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nWe increment the right pointer until we get requried \'1\'s.\nOnce we get it we shrink the window as much as possible by incrementing the left pointer.\n<!-- Describe your approach to solving the problem. -->\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```cpp []\nclass Solution {\npublic:\n    string shortestBeautifulSubstring(string s, int k) {\n        int r = 0;\n\n        int c = 0;\n        int l = 0;\n        string res = "";\n\n        while (r < s.size()) {\n            c += s[r] == \'1\';\n            while (c == k) {\n                string cur = (s.substr(l, r - l + 1));\n                if (res.empty() or res.size() > cur.size() or\n                    (res.size() == cur.size() and cur < res)) {\n                    res = cur;\n                }\n                c -= (s[l++] == \'1\');\n            }\n            r++;\n        }\n\n        return res;\n    }\n};\n```
['C++']