Problem 348691 · medium · Level 03 Linear Management & Searching

Two Drafts After the Deletions

two pointers · strings · simulation

Two clerks copy a word into blank editors, and their key presses are logged as s and t. A # is the delete key: it removes the nearest character to its left that has not been deleted already, and in an empty editor it does nothing. Return True if the two editors end up showing exactly the same text, and False otherwise.

Examples

Input:  s = "bat#ll", t = "bas#ll"
Output: True
Explanation: both editors show "ball".

Input:  s = "ten#", t = "tex"
Output: False
Explanation: the editors show "te" and "tex".

Constraints

  • 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…