Stacks and Queues Matching and cancelling
200. Backspace String Compare
You are given two strings s and t. Each one is a list of keys pressed, in order, in an empty text editor.
A lowercase letter types that letter at the end of the text. A # is the backspace key: it deletes the last
letter of the text, and does nothing if the text is empty.
Return true if pressing the keys of s and pressing the keys of t leave the same text, and false
otherwise. Two empty texts are the same text.
Example 1
Input: s = "plan##ot", t = "plx#ot"
trueExplanation: In s, the two # delete n and then a, which leaves "pl", and "ot" makes it "plot". In t, the #
deletes the x, and the text is "plot" too.
Example 2
Input: s = "tea#n", t = "ten#a"
falseExplanation: Both press the same five keys. But s deletes the a and ends with "ten", while t deletes the n and ends
with "tea".
Example 3
Input: s = "##x#", t = "#"
trueExplanation: The first two # of s find nothing to delete, and the last one deletes the x. Both texts end empty.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ s.length, t.length ≤ 105sandthold lowercase English letters and#only.
Clarifying questions
What you would ask an interviewer before writing any code.