If the given string is S = "lion cow cow lion" and T = βwccwβ, then the string βSβ follows the same pattern as string βTβ.
'Tβ contains only lowercase English letters.
βSβ contains only lowercase English letters and spaces.
βSβ does not contain any trailing or leading spaces. All words in βSβ are separated by a single space.
The first line contains an integer 't' which denotes the number of test cases or queries to be run. Then the test cases follow.
The first line of each test case contains a string βSβ.
The second line of each test case contains a string βTβ.
For each test case, the only line of output will print βYesβ if βSβ follows the same pattern as βTβ. Else print βNoβ.
Print the output of each test case in a separate line.
You are not required to print the expected output, it has already been taken care of. Just implement the function.
1 <= t <= 100
1 <= |S| <= 5000
1 <= |T| <= 5000
Time Limit: 1 second
We will use two hashmaps βcharToWordβ and βwordToCharβ to track which character of βTβ maps to which word of βSβ and which word of βSβ maps to which character of βTβ, respectively.
Here is the algorithm: