Skip to the code
cf.
+10 XP

#250 Compare Typed Text With Backspaces

easy

A typing test records every key press as a string, where # stands for the backspace key. Backspace removes the character before it, if there is one; a backspace on empty text does nothing.

Write sameText(a, b) that returns true if both recordings produce the same final text, and false otherwise.

Example 1

Input: a = "ab#c", b = "ad#c"
Output: true

Both produce ac.

Example 2

Input: a = "a#c", b = "b"
Output: false

The first produces c and the second b.

Constraints

  • 0 <= a.length, b.length <= 200
  • a and b have lowercase letters and #.
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).