All problems
1147MediumStringStackSimulation

Rubbing Letters Off the Tape

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2390Removing Stars From a String

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 tape tape holds lowercase letters and the character *.

Working from left to right, each * rubs itself out along with the nearest letter still standing to its left.

Return what the tape reads once every * has been dealt with. The tape always leaves a letter for each * to rub out.

Examples

Example 1

Input
tape = "abc*d*e"
Output
"abe"

The first star rubs out the c and the second rubs out the d, leaving the a, the b and the e.

Example 2

Input
tape = "aaa***"
Output
""

Each of the three stars rubs out one of the three letters, so nothing is left.

Example 3

Input
tape = "xy*z"
Output
"xz"

The star rubs out the y, and the x and the z close up together.

Constraints

  • 1 <= tape.length <= 10^5
  • every character of tape is a lowercase English letter or *
  • the tape always leaves a letter for each star to rub out

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 remove_stars(tape: str) -> str:
Java
public String removeStars(String tape)
September 7
Apply