Java O(N) Solution
Complexity\n- Time complexity: O(N)\n\n# Code\njava []\nclass Solution {\n    public String shortestBeautifulSubstring(String s, int k) {\n        String res = 
# Complexity\n- Time complexity: O(N)\n\n# Code\n```java []\nclass Solution {\n    public String shortestBeautifulSubstring(String s, int k) {\n        String res = "";\n        Queue<Integer> queue = new LinkedList<>();\n        for (int i = 0; i < s.length(); i++) {\n            if (s.charAt(i) == \'1\') {\n                queue.add(i);\n            }\n            if (queue.size() > k) queue.poll();\n            if (queue.size() == k) {\n                String sub = s.substring(queue.peek(), i + 1);\n                if (res.isEmpty()) {\n                    res = sub;\n                } else {\n                    if (res.length() > sub.length()) {\n                        res = sub;\n                    } else if (res.length() == sub.length()){\n                        res = res.compareTo(sub) > 0 ? sub : res;\n                    }\n                }\n            }\n        }\n        return res;\n    }\n}\n```
['Java']