Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com

Ninja And Typing

Easy
0/40
Average time to solve is 15m
profile
Contributed by
9 upvotes
Asked in companies
Deutsche BankGoldman SachsVMware Inc

Problem statement

Ninja wants to print two strings in a text editor but his keyword allows typing lowercase English letters and backspace only.

Ninja type ‘N’ characters given by string ‘STR1’ to print the first string in the editor, and type ‘M’ characters given by string ‘STR2’ to print the second string. Both ‘STR1’ and ‘STR2’ have lowercase English characters and ‘#’ to denote backspace.

Your task is to return true if both strings that print on the text editor are equal otherwise return false. See the example for more clarity.

Note:
Backspace has no effect on empty text.
Example:
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.
Detailed explanation ( Input/output format, Notes, Images )
Constraints:
1 <= T <= 50
2 <= N <= 10000
0 <= M <= 10000

Time limit: 1 sec
Sample Input 1:
2
ab##  c#d###
ade##c#ba a#ad#b#ba
Sample Output 1:
true
true
Explanation For Sample Input 1:
In the first test case,  Both of them print empty strings.

For the second test case, see the problem statement for an explanation. 
Sample Input 2:
2
a#c b
c#c#c  ccc#c#
Sample Output 2:
false
false
Full screen
Console