Two text fields were typed into an editor where the character # means backspace: it deletes the single character immediately before it, if any. Pressing backspace on an empty field does nothing. Every other character is a normal lowercase letter typed as-is.
Given the raw keystrokes for two fields, decide whether the two fields display the same final text after all backspaces are applied.
Line 1: the raw keystrokes of the first field, a string s (possibly empty).
Line 2: the raw keystrokes of the second field, a string t (possibly empty).
Each string contains only lowercase letters a-z and the character #.
Print YES if the two fields render identical final text, otherwise print NO.
# with no character before it is ignored.Example 1
Input
ab#c ad#c
Expected
YES
Explanation
Field 1 types a, b, backspace (removes b), c -> "ac". Field 2 types a, d, backspace (removes d), c -> "ac". They match, so YES.
Example 2
Input
a#c b
Expected
NO
Explanation
Field 1 renders "c" (a is backspaced away, then c). Field 2 renders "b". They differ, so NO.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →