Panda Guru LogoPanda
Guru

3174. Clear Digits

Round 1

Questions: Specific question not provided.

Follow-up Question

Candidate's Approach
  1. Iterate through the string while maintaining a stack.
  2. If the character is a letter, push it to the stack.
  3. If the character is a digit:
    • Remove the last letter (if any) from the stack.
    • Do not push the digit itself.
  4. The final stack contains the remaining string.

Python Implementation:

class Solution(object): def clearDigits(self, s): """ :type s: str :rtype: str """ stack = [] for char in s: if char.isdigit(): if stack: # Remove the closest non-digit to the left stack.pop() else: stack.append(char) return "".join(stack)

Complexity Analysis:

  1. Time Complexity: O(n) → Single pass through s.
  2. Space Complexity: O(n) → Stack stores at most n characters.
Interviewer's Feedback

No feedback provided.