Best Java Solution || Beats 100%
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\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        int l = 0, r = 0;\n        int onesCount = 0;\n        int shortestLength = INT_MAX;\n        int startIndex = -1;\n        vector<string> ans;\n\n        while (r < s.length()) {\n            if (s[r] == \'1\') {\n                onesCount++;\n            }\n\n            while (onesCount == k) {\n                if (r - l + 1 <= shortestLength) {\n                    if (r - l + 1 < shortestLength) {\n                        ans.clear();  // Start a new set of substrings if shorter\n                    }\n                    shortestLength = r - l + 1;\n                    startIndex = l;\n                    ans.push_back(s.substr(startIndex, shortestLength));\n                }\n\n                if (s[l] == \'1\') {\n                    onesCount--;\n                }\n\n                l++;\n            }\n\n            r++;\n        }\n\n        if (startIndex == -1) {\n            return "";\n        }\n\n        sort(ans.begin(), ans.end());\n\n        for (int i = 0; i < ans.size(); i++) {\n            if (ans[i].length() == shortestLength) {\n                return ans[i];\n            }\n        }\n\n        return "";\n    }\n};\n```
['C++']