String Comparison After Backspaces

STRING

Problem

Given two strings, s and t, this function compares their final versions after simulating backspace operations.

The '#' character represents a backspace, which deletes the preceding character.

The goal is to determine if the two processed strings are identical. If the processed strings are the same, the function returns true; otherwise, it returns false.

Examples

compareStrings("ax##y", "a#y") // true // Why? Both s and t become "y". In s, 'x' is deleted and in t, the first 'a' is deleted compareStrings("##abcd", "abcd##efg###") // false // Why? s will be "abcd" and t will be "ab"
Loading...