Beats 100% in time || Java || Simple || Sliding window solution
Intuition\nWe will use sliding window approach to find all the valid windows ie the window which have k ones in it. And then while doing this we will update ie 
# Intuition\nWe will use sliding window approach to find all the valid windows ie the window which have k ones in it. And then while doing this we will update ie maintain our answer by updating it appropriately if required to update it whenver we find a new valid window\n\n# Approach\nJust use the sliding window approach to find all the valid window containing exacly k ones in them. And maintain a answer variable and whenver we find a new valid window update the answer if the new valid window we found is smaller in size or if equal in size then comapre lexigraphically and then update if new window substring is smaller. And if the new valid window size is greater than the current answer size we dont have to do anything just move on with our sliding window.\n\nFeel free to ask in comments if u r not able to understand any part of the code\n\n \n\n# Complexity\n- Time complexity:\n- O(n)\n\n- Space complexity:\n- O(1)\n\n# Code\n```\nclass Solution {\n    public String shortestBeautifulSubstring(String s, int k) {\n\n\n        int l = 0;\n        int r = 0;\n        int ones = 0;\n        String ans = "";\n        boolean flag = true;\n\n        while(r < s.length()){\n\n            if(s.charAt(r) == \'1\'){\n                ones++;\n            }\n\n            while(ones == k){\n\n                if(flag){\n                    ans = s.substring(l, r+1);\n                    flag = false;\n                }else{\n\n                    String news = s.substring(l,r+1);\n\n                    if(news.length() < ans.length()){\n                        ans = news;\n                    }else if(news.length() == ans.length()){\n                        if(ans.compareTo(news) == 1){\n                            ans = news;\n                        }\n                    }\n\n                }\n\n                if(s.charAt(l) == \'1\'){\n                    ones--;\n                }\n\n                l++;\n\n            }\n\n            r++;\n\n        }\n\n\n        return ans;\n        \n    }\n}\n```
['Java']