Ctrl K

Same Text After Erasing

Easy
Two people type into empty input fields. Their keystrokes are recorded as strings first and second: a lowercase English letter is a typed character, and # is the Backspace key, which deletes the last character. On an empty field, Backspace does nothing. Return True if both fields end up with the same text, and False otherwise.
Example 1
first="cat#r", second="caq#r" → True

The first sequence erases t, the second erases q; both produce car.

Example 2
first="x##y", second="y" → True

The second # hits an empty field and does nothing, then y is typed: both texts are y.

Example 3
first="ab#", second="b" → False

The first gives a and the second gives b, so the texts differ.

Constraints
  • 0 ≤ length of first, second ≤ 200
  • the strings consist of lowercase English letters and #
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsFlip Up to a Letter EasyCollapse Letter Pairs EasyDigits as Backspace EasyErase the Pattern Until It Is Gone MediumSwapping Brackets Into Balance Medium
loading Python…
Input
first="cat#r", second="caq#r"
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 112 tests on the server, hidden ones included.