C++ || Sliding Window
Intuition\nThe smallest beatiful string must start with 1 otherwise there is a smaller beatiful string with the same number of ones strting at 1. Maintain a sli
# Intuition\nThe smallest beatiful string must start with 1 otherwise there is a smaller beatiful string with the same number of ones strting at 1. Maintain a sliding window where the left pointer points to a 1 in the string and the right pointer points to k ones right of the left 1.\n\n# Approach\nUse to pointers to point to a one in the string and k ones right of that one in the string. \n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$ we dont use any additional space other than the variable to return the beatiful string.\n\n# Code\n```\nclass Solution {\npublic:\n    string shortestBeautifulSubstring(string s, int k) {\n        string beatiful="";\n        int st{0},count{0};\n        while(s[st] == \'0\') ++st;\n        int end{st};\n\n        while(st < s.length() && end <s.length())\n        {\n            if(s[end] == \'1\') ++count;\n            ++end;\n\n            if(count == k)\n            {\n                if(beatiful == "") beatiful = s.substr(st, end-st);\n                else if(end-st < beatiful.length()) beatiful =  s.substr(st, end-st);\n                else if(end-st == beatiful.length()) beatiful = min(beatiful,s.substr(st,end-st));\n\n                // if(beatiful.length() == k) return beatiful;\n\n                while(st < s.length() && s[++st] == \'0\') {}\n                --count;\n            }\n        }\n\n        return beatiful;\n    }\n};\n```
['C++']