2904. Shortest and Lexicographically Smallest Beautiful String
You are given a binary string
sand a positive integerk.A substring of
sis beautiful if the number of1‘s in it is exactlyk.Let
lenbe the length of the shortest beautiful substring.Return the lexicographically smallest beautiful substring of string
swith length equal tolen. Ifsdoesn’t contain a beautiful substring, return an empty string.A string
ais lexicographically larger than a stringb(of the same length) if in the first position whereaandbdiffer,ahas a character strictly larger than the corresponding character inb.
- For example,
"abcd"is lexicographically larger than"abcc"because the first position they differ is at the fourth character, anddis greater thanc.
1 | class Solution { |