Typing With Backspace
Two people type on a keyboard where # is the backspace key: it deletes the last character typed, if there is one, and does nothing on an empty screen. Given the keys each person pressed, first and second, return true if both end up with the same text on screen, and false if not.
Examples
first = "ab#c", second = "ad#c" → true
first = "ab##", second = "c#d#" → true
first = "a#c", second = "b" → false
first = "###x", second = "x" → trueIn the first example both type "ac"; in the second, both screens end up empty. In the last, the three backspaces do nothing, since nothing has been typed yet.
Constraints
- Each string holds between 0 and 20,000 characters: lowercase letters and
#. - Aim for O(n) in the length of both strings.
Console
›Run to see what your code prints
Run checks the 4 visible cases here, in your browser. Submit runs all 9 on the judge, 5 of them hidden, and measures how your solution scales.
Expected is the reference solution's answer, from the judge. An input that breaks the statement's other rules may get any answer.