


Backspace has no effect on empty text.
Consider ‘STR1’ = “ade##c#ba”, ‘STR2 = ‘a#ad#b#ba
Both ‘STR1’ and ‘STR2’ print the string “aba” on the text editor, thus we should return true.
The first line contains a single integer ‘T’ representing the number of test cases.
The first line of each test case will contain two space-separated strings ‘STR1’ and ’STR2’ respectively.
For each test case, print “true” if both strings that print on the text editor are equals otherwise print “false”
Output for every test case will be printed in a separate line.
You don’t need to print anything; It has already been taken care of.
1 <= T <= 50
2 <= N <= 10000
0 <= M <= 10000
Time limit: 1 sec
We use a stack to simulate typing of each character. When ninja type backspace we pop the top character from the string otherwise we push the typed character on top of the string.
The steps are as follows:
The basic idea is to Iterate through the string in reverse. If we see a backspace character, the next non-backspace character is skipped. If a character isn't skipped, it is part of the string that is printed on the text editor. We can use a two-pointer-based approach using it to check whether both printed strings will be the same or not.
The steps are as follows: