DSA problem
Backspace String Compare
Given two strings s and t, return true if they are equal when both are typed into empty text editors. The character # means a backspace character.
Note that after backspacing an empty text, the text will continue empty.
Follow-up: Can you solve it in O(n) time and O(1) space?
Examples
Example 1
Input:
s = "ab#c", t = "ad#c"Output:
trueExplanation: Both s and t become "ac". In s the b is deleted by #, in t the d is deleted by #.
Example 2
Input:
s = "ab##", t = "c#d#"Output:
trueExplanation: Both s and t become "" (the empty string).
Example 3
Input:
s = "a#c", t = "b"Output:
falseExplanation: s becomes "c" while t becomes "b", so they are not equal.
Constraints
- 1 <= s.length, t.length <= 200
- s and t only contain lowercase letters and "#" characters.
3 hints and a full solution walkthrough with step-by-step visualizations are available in the practice editor.