Java easy to understand, Beats 100%, Sliding Window
Intuition\nUse sliding window to avoid two loops.\n\n# Code\n\nclass Solution {\n    public String shortestBeautifulSubstring(String s, int k) {\n        List<S
# Intuition\nUse sliding window to avoid two loops.\n\n# Code\n```\nclass Solution {\n    public String shortestBeautifulSubstring(String s, int k) {\n        List<String> resultList = new ArrayList<>();\n        int minLength = s.length();\n        int slow = 0, fast = 0, count = 0; //sliding window\n        while (fast < s.length()) {\n            if (s.charAt(fast) == \'1\') {\n                count++;\n            }\n\n            while (count == k) { //while current window is a match\n                if (minLength > fast - slow + 1) {\n                    resultList = new ArrayList<>(); //empty the resList if find smaller-size matches\n                    minLength = fast - slow + 1;\n                } \n                if (fast - slow + 1 == minLength) {\n                    resultList.add(s.substring(slow, fast + 1));\n                }\n                if (s.charAt(slow) == \'1\') {\n                    count--;\n                }\n                slow++; //increment slow to shrink the window\n            }\n\n            fast++;\n        }\n    \n        if (resultList.size() == 0) {\n            return "";\n        }\n        Collections.sort(resultList);\n        return resultList.get(0);\n    }\n}\n```
['Sliding Window', 'Java']