Typing with backspace
Two people type on a keyboard where # is the backspace key (it deletes the previous character, if any). Given what each typed, print YES if they end up with the same text, otherwise NO.
Reported in: TCS NQT (memory-based)
Input
Two lines, one typed string each.
Output
YES or NO.
Constraints
1 ≤ length ≤ 10^5.
Example 1
Input:
ab#c
ad#c
Output:
YESExample 2
Input:
a#c
b
Output:
NOHint: Build each final text with a stack: push letters, pop on #.