The first line contains a single integer βTβ representing the number of test cases.
The first line of each test case contains three strings, and the first two strings, i.e. βFIRSTβ and βSECONDβ are the strings which he was given at the beginning, and the third string is βTHIRDβ, which was given by the professor.
For each test case, you have to return βYESβ if all characters are present in the third string of the first and second strings; else, return βNOβ.
Print the output of each test case in a separate line.
You donβt need to print anything; It has already been taken care of.
1 <= T <= 10^2
1 <= |FIRST|, |SECOND|, |THIRD| <= 10^5
Time Limit: 1 sec
The basic idea of this approach is that we will initially iterate through both the strings (βFIRSTβ and βSECONDβ) and for all the characters present in them we will try to remove the same character from βTHIRDβ. So, after every iteration, one character from string βTHIRDβ will be removed and if the letter is not found in between then we will return βNOβ. At last, we will check that if string βTHIRDβ becomes empty that means that all characters match and will return βYESβ or else will return βNOβ as few extra characters are present in string βTHIRDβ.
Here is the algorithm:
The basic idea of this approach is to count the number of total occurrences of each letter in strings βFIRSTβ, βSECONDβ and βTHIRDβ. Then, we will check for all the letters present, whether the sum of occurrences of the first two strings is the same as the third or not. If all the occurrences of all letters are the same then at last we will return βYESβ or else we will return βNOβ.
Here is the algorithm: