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: