5-liner in Python3
Don\'t do this in an interview lol. This is just for fun.\n\nThis solution abuses Big Integer in Python3 so that we can compare both the length and the lexograp
Don\'t do this in an interview lol. This is just for fun.\n\nThis solution abuses Big Integer in Python3 so that we can compare both the length and the lexographic order at the same time. We do this by left shifting the length by 100 and adding the number itself. That way, the smallest length will always come first, and if there is a tie, we compare the number itself.\n\nLet me know if you have any questions!\n\n```\nclass Solution:\n    def shortestBeautifulSubstring(self, s: str, k: int) -> str:\n        l, ones, res = 0, 0, \'0\' * 101\n        for i, b in enumerate(s):\n            ones += b == \'1\'\n            while ones == k: l, ones, res = l + 1, ones - (s[l] == \'1\'), min(res, s[l: i + 1], key=lambda x: len(x) << 100 | int(x, 2))\n        return res * (len(res) != 101)\n```
['Python', 'Python3']