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

Problem

You are given a string s. Your task is to remove all digits by doing this operation repeatedly:
  • Delete the first digit and the closest non-digit character to its left.
Return the resulting string after removing all digits. Note that the operation cannot be performed on a digit that does not have any non-digit character to its left.

Examples

Constraints

  • 1 <= s.length <= 100
  • s consists only of lowercase English letters and digits.
  • The input is generated such that it is possible to delete all digits.

Solution

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

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026