Python sliding window solution: Time beats 66% of solutions[Feedback appreciated]
Intuition\n Describe your first thoughts on how to solve this problem. \n        # review\n        # it is a binary digits\n        # we want to find the shorte
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n        # review\n        # it is a binary digits\n        # we want to find the shortest substring with exactly k number of 1s\n            # there are constraints\n            # the substring must be the shortest\n            # if there are multiple substrings, return the         lexicographly shorter one\n# Approach\n<!-- Describe your approach to solving the problem. -->\n    # approach:\n        # if there are no 1s or the count of 1 in s is < k:\n            # then there\'s no beautiful string\n        # # Using this example: \n        # """\n        # 1. The substring "100011001".\n        # 2. The substring "100011001".\n        # 3. The substring "100011001".\n        # 4. The substring "100011001".\n        # 5. The substring "100011001".\n        # 6. The substring "100011001".\n        # 7. The substring "100011001".\n        # """\n        # once we have found k amount of 1s in a substring\n        # we don\'t need to increase the substring as subsequent\n        # additions to the substr will make it longer\n        # what we want to do is to save this substring to a temp var\n        # then we can move to the next char in the string\n        # and keep looking for another substring to meet the req\n        # that\'s shorter or lexicographically smaller\n        # when we want to change the window, can we shrink it?\n        # we can shrink it while the count of 1s is either 0 or \n        # == k depending on how we implement count\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```\nclass Solution:\n    def shortestBeautifulSubstring(self, s: str, k: int) -> str:\n        # edge case\n        if len(s) == 0 or s.count("1") < k:\n            return ""\n        \n        # full\n        count = 0 \n        res = ""\n        start = 0\n        for i in range(len(s)):\n            if s[i] == "1":\n                count += 1\n            if count == k:\n                # get the current substring\n                substr = s[start:i+1]\n                # print(substr)\n                # print(res)\n                # print(substr)\n                if res == "":\n                    res = substr\n                elif len(res) == len(substr):\n                    print(res)\n                    print(substr)\n                    if res > substr:\n                        print(res)\n                        print(substr)\n                        res = substr\n                # print(res)\n                while count == k:\n                    substr = s[start:i+1]\n                    if len(res) > len(substr):\n                        # if res > substr:\n                        res = substr\n                    elif len(res) == len(substr):\n                        if res > substr:\n                            # print(res)\n                            # print(substr)\n                            res = substr\n                    # print(s[start:i+1])\n                    curr = int(s[start])\n                    count -= curr\n                    start += 1\n                print(s[start:i+1])\n        return res\n\n        # review\n        # it is a binary digits\n        # we want to find the shortest substring with exactly k number of 1s\n            # there are constraints\n            # the substring must be the shortest\n            # if there are multiple substrings, return the lexicographyly\n            # shorter one\n        # approach:\n            # if there are no 1s or the count of 1 in s is < k:\n                # then there\'s no beautiful string\n            # # Using this example: \n            # """\n            # 1. The substring "100011001".\n            # 2. The substring "100011001".\n            # 3. The substring "100011001".\n            # 4. The substring "100011001".\n            # 5. The substring "100011001".\n            # 6. The substring "100011001".\n            # 7. The substring "100011001".\n            # """\n            # once we have found k amount of 1s in a substring\n            # we don\'t need to increase the substring as subsequent\n            # additions to the substr will make it longer\n            # what we want to do is to save this substring to a temp var\n            # then we can move to the next char in the string\n            # and keep looking for another substring to meet the req\n            # that\'s shorter or lexicographically smaller\n            # when we want to change the window, can we shrink it?\n            # we can shrink it while the count of 1s is either 0 or \n            # == k depending on how we implement count\n\n```
['Python3']