Clear Digits

You are given a string `s` of lowercase letters and digits. Repeatedly delete the first digit together with the closest non-digit character to its left, until no digits remain. Return the resulting string. The input always allows every digit to be removed this way.

30:00

Clear Digits
easy
Free written solution
Topics
Companies

You are given a string s of lowercase letters and digits. Repeatedly delete the first digit together with the closest non-digit character to its left, until no digits remain. Return the resulting string. The input always allows every digit to be removed this way.

Example 1:
Input: {"s":"abc"}
Output: abc
Constraints:
  • 1≤s.length≤1001 \leq s.\text{length} \leq 100

  • s consists only of lowercase English letters and digits.

  • The input is generated such that it is possible to delete all digits.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"s":"abc"}

keystrokes in s: letters type, digits act as ⌫

a
b
c

Treat the string as keystrokes: a letter types itself, a digit works like backspace and deletes the closest letter still on screen to its left. The screen is a stack.

screen (a stack: the cursor is the top)

backspaces 0
on screen 0
Variables
VariableValue
stack
DepthFunction Call
Stack empty
0/7