Skip to content
Decoder

Removing Stars From a String

Medium

Problem

You get a string s of lowercase letters and stars *. Each star works like a backspace: it deletes the closest non-star character to its left, and the star itself disappears too. Apply every star and return the string that is left.

Example 1

Input
s = "leet**cod*e"
Output
"lecoe"

Example 2

Input
s = "erase*****"
Output
""

In the first example the two stars remove t and e, and the third removes d.

Constraints

  • 1 <= s.length <= 10^5
  • s has only lowercase letters and *.
  • Every star always has a character to delete.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.