text, an integer length, a letter letter and an integer times.
Pick exactly length characters from text while keeping their order (a subsequence), such that letter appears among them at least times times. Of all such subsequences, return the lexicographically smallest one, the one that would come first in a dictionary.
It is guaranteed that letter occurs in text at least times times, so an answer always exists.text="banana", length=3, letter="n", times=2 → 'ann'
Two of the three letters must be n, and the third should be as small as possible: an a before two ns gives ann.
text="zebra", length=2, letter="z", times=1 → 'za'
The z is mandatory and sits at the very start, so it comes first. After it we take the smallest remaining letter, a.
text="cabbac", length=4, letter="c", times=2 → 'caac'
times ≤ length ≤ len(text) ≤ 5 · 10⁴text consists of lowercase English lettersletter is a lowercase English letter that occurs in text at least times timestext="banana", length=3, letter="n", times=2
'ann'
Run checks the first 3 tests in your browser. Submit checks all 46 tests on the server, hidden ones included.