Problem 24 of 75

Removing Stars From a String

MediumNot solved yetInterview me on this
Before you code · which pattern fits?

The problem

You are given a string s containing stars '*'. In one operation, choose a star, remove the closest non-star character to its left, and remove the star itself. Return the string after all stars have been removed.

"leet**cod*e" → "lecoe" "erase*****" → ""

Your solution runs against 2 unit tests, including edge and large-value cases.

Loading...

Test console · 2 unit tests

Submit your code to run it against all 2 unit tests. Results appear here.

JavaScript, TypeScript & Python run sandboxed in your browser; other languages run on the execution server. Your code is saved locally as you type.

Hint

Reference solution

Video explanation

Removing Stars From a String, explainedNeetCodeIO