2904. Shortest and Lexicographically Smallest Beautiful String
You are given a binary string
s
and a positive integerk
.A substring of
s
is beautiful if the number of1
‘s in it is exactlyk
.Let
len
be the length of the shortest beautiful substring.Return the lexicographically smallest beautiful substring of string
s
with length equal tolen
. Ifs
doesn’t contain a beautiful substring, return an empty string.A string
a
is lexicographically larger than a stringb
(of the same length) if in the first position wherea
andb
differ,a
has 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, andd
is greater thanc
.
1 | class Solution { |