Skip to main content
LeetCode 2390, Medium. Topics: String, Stack, Simulation. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 14 parametrized pytest cases, and a playground notebook:

Problem

You are given a string s, which contains stars *. In one operation, you can:
  • Choose a star in s.
  • Remove the closest non-star character to its left, as well as remove the star itself.
Return the string after all stars have been removed. Note:
  • The input will be generated such that the operation is always possible.
  • It can be shown that the resulting string will always be unique.

Examples

Constraints

  • 1 <= s.length <= 10^5
  • s consists of lowercase English letters and stars *.
  • The operation above can be performed on s.

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026