Lexicographically Minimum String After Removing Stars
Real-world version: Clearing the Markers Off the StripThe statement here is our own: the same inputs, outputs and technique.
A strip strip holds lowercase letters and the marker character *.
Every marker has to come off the strip, and taking one off also takes off one letter standing to its left. That letter must be one of the smallest letters still standing to the marker's left, and when several of them tie you may take off whichever you please.
Return the smallest word the surviving letters can spell, ordered as a dictionary would. The strip always leaves enough letters for every marker to come off.
Examples
Example 1
- Input
- strip = "abab*"
- Output
- "abb"
The smallest letter to the marker's left is a and two of them stand there. Taking off the later one leaves an a nearer the front, which reads smaller.
Example 2
- Input
- strip = "ab*"
- Output
- "b"
The smallest letter to the marker's left is a, so it goes off along with the marker.
Example 3
- Input
- strip = "aabb**"
- Output
- "bb"
The first marker takes off the later a and the second marker takes off the other one, leaving the two b letters.
Constraints
- 1 <= strip.length <= 10^5
- every character of strip is a lowercase English letter or *
- the strip always leaves enough letters for every marker to come off
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def clear_stars(strip: str) -> str:public String clearStars(String strip)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Reorganize StringReal-world version: Paint Line ShuffleMedium
- Using a Robot to Print the Lexicographically Smallest StringReal-world version: Typesetter's RackMedium
- Construct String With Repeat LimitReal-world version: Largest Banner Under a Run CapMedium
- Longest PalindromeReal-world version: Longest Lintel Row of Carved TilesEasy