Typing With Backspace

EasyStack≈ 15 min

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

text
first = "ab#c", second = "ad#c"   →  true
first = "ab##", second = "c#d#"   →  true
first = "a#c", second = "b"       →  false
first = "###x", second = "x"      →  true

In 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.
Sound off. Turn on for key clicks and a chime when the tests pass.Inline suggestions off. Recommended while you are learning. Turn on to complete words as you type.
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.