Ninja is going to visit her friend Mico. He is thinking to gift her a string. But he came to know that Mico only likes the string 'S'. Ninja already has a string 'K'. Now, Ninja can change the string 'K' in some other string by choosing any character in one move and change all its occurrence with any other lowercase English character. He can do this several times.
Help Ninja to find if he can change his string 'K' to string 'S', which Mico likes.
Note:Both 'S' and 'K' contain only lowercase English characters.
For Example:
K = "aabb" and S = "bbcc"
Now Ninja can do the following changes:
- Change βbβ to βcβ -> βaaccβ
- Change βaβ to βbβ -> βbbccβ
Hence Ninja can give Mico the desired gift.
The first line of input contains an integer βTβ denoting the number of test cases to run. Then the test case follows.
The first line of each test case contains a string 'S'.
The next line of each test case contains a string 'K'.
Output Format
For each test case, if Ninja can convert K into S, return βTrueβ else return βFalseβ.
Note:
You donβt need to take any input or print anything. This already has been taken care of. Just implement the function.
1 <= T <= 5
1 <= |K|, |S| <= 10^5
Time Limit: 1 second
2
aabcc
ccdaa
ninjas
coding
True
False
Test case 1:
Here K=ccdaa and S=aabcc. Here we can change K into S by following conversions
Change βdβ to βbβ -> ccbaa
Change βaβ to βeβ -> ccbee
Change βcβ to βaβ -> aabee
Change βeβ to βcβ-> aabcc
Test case 2:
It is not possible to change K to S by any number of conversions.
2
code
dope
acbz
acbza
True
False
Think of mapping each character in βKβ to the character in βSβ at corresponding positions in βSβ.
Algorithm:
O(N), where βNβ is the size of string βKβ.
Here we are iterating over the length of string βKβ. Hence the complexity is O(N).
O(1)
Constant space is used.