You are given a binary string s and a positive integer k. A substring of s is beautiful if the number of 1's in it is exactly k. Let len be the length of the shortest beautiful substring. Return the lexicographically smallest beautiful substring of string s with length equal to len. If s doesn't contain a beautiful substring, return an empty string. A string a is lexicographically larger than a string b (of the same length) if in the first position where a and b differ, a has a character strictly larger than the corresponding character in b. For example, "abcd" is lexicographically larger than "abcc" because the first position they differ is at the fourth character, and d is greater than c.
Example 1
Input: s = 100011001, k = 3
Output: 11001
Explanation: The shortest beautiful substrings have length 5; among those, "11001" is lexicographically smallest.
Example 2
Input: s = 1011, k = 2
Output: 11
Explanation: Shortest beautiful substring has length 2, and "11" is the smallest such.
Example 3
Input: s = 000, k = 1
Output:
Explanation: There are no 1's, so no beautiful substring exists.
A shortest beautiful substring must begin and end with a '1' (any leading or trailing '0' can be trimmed while keeping exactly k ones and shrinking the length). So slide a window that carries at most k ones: strip leading zeros and drop surplus ones from the left, and whenever the window holds exactly k ones it is a candidate. Keep the best by length, breaking ties lexicographically.
Run checks all cases above. Submit evaluates all test cases.