Clear Digits

Easy Topics Company Tags

While s contains a digit, remove the leftmost digit together with the closest remaining letter to its left. Return the string after all digits have been removed. The input guarantees that a letter is available for every removal.

Example 1:

Input: s = "a"

Output: "a"

Explanation: There is no digit to trigger a removal, so "a" remains.

Example 2:

Input: s = "a0"

Output: ""

Explanation: Remove the digit "0" and the closest letter to its left, "a". The string becomes empty.

Example 3:

Input: s = "abc123"

Output: ""

Explanation: Remove "1" with "c", then "2" with "b", and finally "3" with "a". Every character is removed.

Constraints:

  • 1 <= s.length <= 100
  • Only lowercase English letters and digits occur. Every digit has an available letter to its left to remove.


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.