You are given three strings 'A', 'B' and 'C'. Check whether 'C' is formed by an interleaving of 'A' and 'B'.
'C' is said to be interleaving 'A' and 'B', if the length of 'C' is equal to the sum of the length of 'A' and length of 'B', all the characters of 'A' and 'B' are present in 'C' and the order of all these characters remains the same in all three strings.
For Example:If A = “aab”, 'B' = “abc”, 'C' = “aaabbc”
Here 'C' is an interleaving string of 'A' and 'B'. because 'C' contains all the characters of 'A' and 'B' and the order of all these characters is also the same in all three strings.

If 'A' = “abc”, 'B' = “def”, 'C' = “abcdefg”
Here 'C' is not an interleaving string of 'A' and 'B'. 'B'ecause neither A nor 'B' contains the character ‘g’.
The first line contains an integer 'T' which denotes the number of test cases or queries to be run. Then, the T test cases follow.
The first and only line of each test case contains three strings 'A', 'B' and 'C' each separated by a single space.
Output format:
For each test, print True, if 'C' is an interleaving string of 'A' and 'B, otherwise print False in a separate line.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= |'A'|, |'B'| <= 150
1 <= |'C'| <= 300
where |A|, |'B'|, |'C'| denotes the length of string 'A', 'B' and 'C' respectively.
All the characters of the strings 'A', 'B' and 'C' contain lowercase English letters only.
Time limit: 1 sec
2
abdd fef abfddef
aab abc aabbc
True
False
For the first test case, all the characters of A and B are present in C, in the same order.
For the second case,'C' < ('A' + 'B').
2
zxry qwr qwzxxryr
a a aa
False
True
For the first test case, 'C' > ('A' + 'B').
For the second test case, all the characters of A and B are present in C in the same order.
Think of a brute force solution using recursion.
Approach:
In order to solve this problem, let us solve a smaller problem first. Let’s assume that the length of the string A and B is 1 and the length of the string C is 2. Now in order to check whether C is formed by interleaving A and B or not, we consider the last character of string C and if this character matches neither with the character of the string A nor with the character of string B, then we return false. But if it matches with any of the characters either from A or from B, we check the same for the other character in C. So, let's further expand this idea, for bigger problems. So, if the last character of C, matches with either the last character of A or B, we check recursively for the second last element and then the third last element and so on, until we finally reach the base case when all the strings eventually become empty.
bool isInterleaveUtil( A, B, C, n1, n2, n3):
O(2^(N + M)), where N is the length of the string A and M is the length of string B.
In the worst case, for every character of the input strings A and B, there can be two choices. Hence, the time complexity will be O(2^(N + M)).
O(N + M), where N is the length of the string A and M is the length of string B.
In the worst case, the size of stack for recursive calls can go upto (N + M). Hence the overall complexity will be O(N + M).