Last Updated: 25 Nov, 2020
##### Amazing Strings
Easy
Problem statement

#### Note: The strings contain only uppercase Latin characters.

##### Input Format:
``````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.
``````
##### Output Format:
``````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.
``````
##### Note:
``````You donβt need to print anything; It has already been taken care of.
``````
##### Constraints:
``````1 <= T <= 10^2
1 <= |FIRST|, |SECOND|, |THIRD| <= 10^5

Time Limit: 1 sec
``````
Approaches

## 01Approach

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:

1. Declaring an array of size equal to length of the string βTHIRDβ and assigning them value as 0.
2. Iterating from starting of string βFIRSTβ to ending of it.
• Declare a temporary variable named βTEMPβ to keep track of the current character and initialize it with 0.
• Check for the first occurrence of that particular character in the string βTHIRDβ.
• If the character matches the current character of βFIRSTβ and also the current character is not visited them we got the corresponding character for the current character.
• Mark current index as visited and change of βTEMPβ variable to 1 as it indicates that corresponding character is found and break the loop.
• If βTEMPβ is still 0 that means that the corresponding character is not found and so, return βNOβ.
3. Iterating from starting of string βSECONDβ to ending of it.
• Declare a temporary variable named βTEMPβ to keep track of the current character and initialize it with 0.
• Check for the first occurrence of that particular character in the string βTHIRDβ.
• If the character matches the current character of βSECONDβ and also the current character is not visited them we got the corresponding character for the current character.
• Mark current index as visited and change of βTEMPβ variable to 1 as it indicates that corresponding character is found and break the loop.
• If βTEMPβ is still 0 that means that the corresponding character is not found and so, return βNOβ.
4. After iterating both the strings βFIRSTβ and βSECONDβ, we will check that if any character is still unvisited or not.
5. If any character is found not visited then we will return βNOβ, else βYESβ.