let A = a, B = ac, C = ac.
Now In this example, we can take whole string B to form C or take substring {a} and substring {c} from A and B, respectively to make C. Hence the answer is 2.
The first line contains a single integer ‘T’ denoting the number of test cases to be run. Then each test cases follow.
The first line of each test case contains a string ‘A’.
The Second line of the test case contains the string ‘B’.
The third line of the test case contains the string ‘C’.
For each test case, print a single integer ‘ANS’ representing the number of ways.
Output for each test case will be printed in a separate line.
You are not required to print anything; it has already been taken care of. Just implement the function and return the answer.
1 <= T <= 5
1 <= |A|, |B|, |C| <= 100, where |S| represents the length of the String S.
Time limit: 1 sec
The basic idea is to go through every element of the string A and B and check if the current element equals any element at some position in string C.
The steps are as follows:
This approach is same as the naive approach. The only difference is we will store all the results in an array dp to avoid repetitions.
The steps are as follows:
In this approach, we will iterate over both the strings and check if the current element of the string matches with the current element of the final string and update the dp array.
NINJA AND HAPPINESS
DECODE STRING
Randomly Sorted
Search In A Sorted 2D Matrix
Spiral Matrix