
You are provided with the content written in the letter. The content of the letter will only contain the English alphabets, non-negative integers, and white spaces. It is guaranteed that the content will have the first character as the English alphabet or a non-negative integer.
The first line contains a single integer ’T’ representing the number of test cases.
The first line of each test case will contain the string ‘S’ which represents the content written in the given letter.
The second line of each test case will contain the string ‘X’ which represents the word ‘X’.
The third line of each test case will contain the string ‘R’ which represents the word ‘R’.
For each test case, return the decoded content of the given letter or we can say return the new content of the letter in which all occurrences of the word ‘X’ is replaced by the word ‘R’.
You don’t need to print anything, It has already been taken care of. Just implement the given function.
1 <= T <= 50
1 <= |S| <= 10^4
1 <= |X| <= |S|
1 <= |R| <= |S|
Where '|S|', '|X|', '|R|' denotes the length of the string 'S', 'X', 'R' respectively.
Time limit: 1 sec
The basic idea is to iterate through the content and whenever find the word ‘X’ just replace it with the word ‘R’. We will not be going to change the string that represents the content instead of that we create another string to store the decoded content.
The steps are as follows:
The basic idea is to create the longest proper prefix and suffix array for word ‘X’ and then apply the KMP algorithm to find the occurrences of word ‘R’ in the content.
The steps are as follows: