FunctionRacerProblemsRace

Smallest Pick With a Letter Quota

HardStacks and queuesPython, JavaScript, TypeScript, Java, C++

Pick exactly k characters of text and keep them in their order. The pick must hold the character letter at least quota times.

Return the alphabetically smallest pick. text always holds letter at least quota times.

Example 1

text "banana"
k 3
letter "n"
quota 1
returns "aan"

aaa would be smaller, but it has no n. aan takes two a's and the n that follows them.

Example 2

text "cabz"
k 2
letter "c"
quota 1
returns "ca"

The only c is the first character, so the pick is c followed by the smallest later letter.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Stacks and queues problems