Compare Two Docs Keystroke Logs That Include Backspaces
Last updated: November 29, 2026
Quick Overview
Two keystroke logs from a collaborative editor use '#' to mean backspace. Return whether both logs produce the same final text, using O(1) extra space.
0
0
0 solved
Two keystroke logs from a collaborative editor use '#' to mean backspace. Return whether both logs produce the same final text, using O(1) extra space.
Framed around replaying editor input in Google Docs, this is a Google technical-screen favorite because the stack solution is easy but the O(1) space follow-up needs careful backward pointers. The interviewer checks whether the candidate can manage a skip counter on each string without off-by-one bugs.
What the Interviewer Expects
- Gives the stack solution first and states its O(n) space
- Scans both strings from the end with skip counters
- Correctly handles backspaces that delete other backspaces' targets
- Handles backspaces at the start of a log
- Compares one visible character at a time
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you support a delete-word key that removes back to the previous space?
- What if the log also contains cursor-left and cursor-right moves?
- How would you stream two very long logs from disk?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: strings
aandbwith lowercase letters and#. #deletes the previous visible character, or does nothing if there is none.- Output: whether the final texts are equal.
- Target O(n +...
High-Level Design
Reading forward needs a stack because you do not know yet whether a character will be deleted. Reading backward fixes that: when you see #, increment a skip counter; when you see a letter while `s...