Problem 348691 · medium · Phase 03 Linear Management & Searching

Typed Text Equality With Backspaces

two pointers · strings · simulation

Two people type into empty editors; a # in the typed sequence means the backspace key (deleting the previous surviving character, or doing nothing if the editor is empty). Given the two typed sequences s and t, return True if the editors end up showing the same text.

Examples

Input:  s = "ab#c", t = "ad#c"
Output: True
Explanation: both editors show "ac".

Input:  s = "a#c", t = "b"
Output: False

Constraints

  • 0 <= len(s), len(t) <= 10**5, lowercase letters and #
  • Target: O(len(s) + len(t)) time, O(1) extra space (do not build the final texts).

Goals

  • Process a string from the back so backspaces can be resolved without a buffer
  • Write a helper that finds the next surviving character on each side
Starting Python…