Backspace String Compare

Easy Topics Company Tags

Treat each of s and t as a sequence typed into its own initially empty editor. A lowercase letter appends that letter, and # removes the most recently entered letter if one exists. A backspace in an empty editor leaves it empty. Return true if the two resulting texts are equal, and false otherwise.

Example 1:

Input: s = "xy#z"
t = "xz"

Output: true

Explanation: In the first editor, # removes y, leaving xz. The second editor also contains xz, so the texts are equal.

Example 2:

Input: s = "###"
t = "a#"

Output: true

Explanation: Backspaces applied to an empty editor have no effect. The first text stays empty, and a# deletes its only letter, so both results are empty.

Example 3:

Input: s = "ab#"
t = "ab"

Output: false

Explanation: The first text becomes a after deleting b. The second remains ab, so the results are different.

Constraints:

  • 1 <= s.length, t.length <= 200
  • Both strings contain only lowercase English letters and #.


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.