All problems
1126MediumHash TableStringStackGreedyHeap (Priority Queue)

Clearing the Markers Off the Strip

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3170Lexicographically Minimum String After Removing Stars

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def clear_stars(strip: str) -> str:
Java
public String clearStars(String strip)
September 7
Apply