Beats 100 percent | Sliding window solution with two pointers
\n\n# Code\n\nclass Solution {\n    public String shortestBeautifulSubstring(String s, int k) {\n        int count = 0;\n        int left = 0, right = 0;\n     
\n\n# Code\n```\nclass Solution {\n    public String shortestBeautifulSubstring(String s, int k) {\n        int count = 0;\n        int left = 0, right = 0;\n        int minLen = Integer.MAX_VALUE;\n        String minString = "";\n        while (left < s.length()) {\n            while (right < s.length() && count != k) {\n                if (s.charAt(right) == \'1\') {\n                    count++;\n                }\n                right++;\n            }\n            \n            int currLen = right - left + 1;\n            if (count == k && currLen <= minLen) {\n                minLen = currLen;\n                String str = s.substring(left, right);\n                if (minString.length() == str.length() && minString.compareTo(str) < 0){\n\n                } else {\n                    minString = str;\n                }                \n            }\n            if (s.charAt(left) == \'1\') {\n                count--;\n            }\n            left++;\n        }\n        return minString;\n    }\n}\n```
['Two Pointers', 'String', 'Sliding Window', 'Java']