Smallest Pick With a Letter Quota
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
1 <= quota <= k <= len(text) <= 60textholds lowercase letters andletteris one lowercase letterletterappears at leastquotatimes intext
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Stacks and queues problems
- Tiny Language With LetHard
- Value of a Logic FormulaHard
- Close Every BracketBeginner
- Crate PileBeginner
- Dead-End DrivewayBeginner
- Elevator TripsBeginner
- Flip the PancakesBeginner
- Last In, First OutBeginner