Two players enter their names on an arcade's high-score screen, which starts blank. Their button presses are logged as the strings a and b: a lowercase letter adds that letter, and # is the delete button, which wipes the most recent letter still on screen (on a blank screen it does nothing).
Return True if both screens finish showing the same text, otherwise False.
Examples
Input: a = "cat#r", b = "cab#r"
Output: True
Explanation: both screens end with "car".
Input: a = "dog##e", b = "#de"
Output: True
Explanation: both screens end with "de".
Input: a = "go#", b = "o"
Output: False
Explanation: the screens end with "g" and "o".
Constraints
0 <= len(a), len(b) <= 10**4- Characters are lowercase letters or
# - Target:
O(len(a) + len(b))time
Goals
- Simulate a backspace key with a stack of characters
- Reduce both inputs to their final form before comparing
- Handle a backspace pressed on an empty buffer