Just compare starting from the end of the strings. When you see "-B" (possibly consecutively), you know you can skip stuff. O(n) time and O(1) space.
The fact that backspace is two characters and the keypresses are separated by commas is gross. It would be so much nicer (and realistic) for the input be an ASCII string with literal backspace characters.
Important thing when just skipping:
lets say we have "a,c,-B,-B" and we start from the back: we see a -B, so we skip the next character, now there is a c and then an a so we get ca (reversed), which is wrong. You need to count the -B s that are back to back and then remove as many "chars". also agree, real chars would be far better, also returning literal "true" and "false" hurts a lot
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Just compare starting from the end of the strings. When you see "-B" (possibly consecutively), you know you can skip stuff. O(n) time and O(1) space.
The fact that backspace is two characters and the keypresses are separated by commas is gross. It would be so much nicer (and realistic) for the input be an ASCII string with literal backspace characters.
Important thing when just skipping:
lets say we have "a,c,-B,-B" and we start from the back: we see a -B, so we skip the next character, now there is a c and then an a so we get ca (reversed), which is wrong. You need to count the -B s that are back to back and then remove as many "chars". also agree, real chars would be far better, also returning literal "true" and "false" hurts a lot