✅🔥100% || 0ms✅Using Sliding Window🪟✅2904. Shortest and Lexicographically Smallest Beautiful String
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
# 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        ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);\n        string ans = "";\n        int l = 0, r = 0, cntOnes = 0;\n        while(r < s.size()) {\n            cntOnes += (s[r] - \'0\');\n            if(cntOnes == k) {\n                while(s[l] == \'0\') {\n                    ++l;\n                }\n                string str = s.substr(l, r - l + 1);\n                if(ans == "" || str.size() < ans.size() || (str.size() == ans.size() && ans > str)) {\n                    ans = str;\n                }\n                --cntOnes;\n                ++l;\n            }\n            ++r;\n        }\n        return ans;\n    }\n};\n```
['C++']