Easy · Reverse Two Pointers
Understand → Visualise → Practice.
Hash acts as a backspace. Return whether two typed strings produce equal final text.
Read both strings backwards. Keep a count of pending backspaces; skip characters they delete. Compare the next surviving characters of both strings.
Use one index per string, starting at the end.
A '#' adds one to the skip count; a normal character with skips pending is skipped.
The next visible characters must be equal; both strings must run out together.
O(n + m) time and O(1) space.
A '#' at the start of a string deletes nothing; don't let the skip count go wrong there.
Read the full guide first: Two Pointers and Sliding Windows.
Guest mode lets you understand, visualise and run the sample tests. Create a free account to submit and save your solutions.