Sliding window
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```\n\nclass Solution {\n\n       public String shortestBeautifulSubstring(String s, int k) {\n        int beautifulCharCnt = 0;\n        int curBeginIdx = 0;\n        int curEndIdx = 0;\n        var globalShortest = "";\n        int length = s.length();\n        while (curBeginIdx < length && curEndIdx < length + 1) {\n            if (beautifulCharCnt < k) {\n                if (curEndIdx < length && s.charAt(curEndIdx) == \'1\') {\n                    beautifulCharCnt++;\n                }\n                curEndIdx++;\n            } else {\n                String currentBeautiful = s.substring(curBeginIdx, curEndIdx);\n                globalShortest = findShortest(globalShortest, currentBeautiful);\n                if (s.charAt(curBeginIdx) == \'1\') {\n                    beautifulCharCnt--;\n                }\n                curBeginIdx++;\n            }\n        }\n        return globalShortest;\n    }\n\n    private String findShortest(String s1, String s2) {\n        if (s1.isEmpty()) {\n            return s2;\n        }\n        if (s2.isEmpty()) {\n            return s1;\n        }\n        if (s1.length() != s2.length()) {\n            return s1.length() > s2.length() ? s2 : s1;\n        }\n        return s1.compareTo(s2) > 0 ? s2 : s1;\n    }\n}\n```
['Java']