Given a string 'S' and a list 'wordList' that consists of 'N' distinct words. Let 'Wi' denote word at index 'i' in 'wordList'. For each word 'Wi' in 'wordList', you need to determine whether it is present in string 'S' or not. Return a boolean array, where a boolean value at index ‘i’ represents whether the word ‘Wi’ is present in the string ‘S’ or not.
The first line of input contains an integer ‘T’ denoting the number of test cases.
The next ‘3*T’ lines represent the ‘T’ test cases.
The first line of each test case contains the string ‘S’.
The second line of each test contains an integer ‘N’ representing the number of words in the ‘wordList’.
The third line of each test case contains the ‘N’ space-separated strings representing the words in the ‘wordList’.
Output Format :
For each test case, print a boolean array where the value at index ‘i’ is ‘True’ if the word at index ‘i’ in the ‘wordList’ is present in string ‘S’ Otherwise, it is ‘False’.
Note :
1. String ‘S’ consists of lowercase, uppercase alphabets, and spaces.
2. String ‘Wi’ consists of lowercase and uppercase alphabets only.
3. The word, ‘Wi’ is case sensitive.
4. You can’t use language-built-in string-matching methods.
5. Don’t print anything, just return the boolean array determining the presence or absence of the words present in ‘wordList’.
1 <= T <= 50
1 <= |S| <= 10^3
1 <= N <= 10^3
1 <= |W| <= 10
Where ‘|S|’ denotes the length of string and |W| denotes the maximum length of the word present in ‘wordList’.
Time limit: 1 sec
2
This is a large String
4
This this is age
ILikeCodingNinjas
3
Ninja Coding Code
True False True False
True True False
Test case 1:
Here String ‘S’ is “This is a large String” and ‘wordList’ is [“This”, “this”, “is”, “age”]
The word “This” is present from index ‘0’ to index ‘3’ in ‘S’.
The word “this” is not present in ‘S’.
The word “is” is present from index ‘2’ to index ‘3’’ and from ‘5’ to index ‘6’ in ‘S’.
The word “age” is not present in ‘S’.
Note: All words are case sensitive and we consider 0 based indexing in 'S'.
Test case 2:
Here String ‘S’ is “ILikeCodingNinjas” and ‘wordList’ is [“Ninja” “Coding” “Code”]
The word “Ninja” is present from index ‘11’ to index ‘15’ in ‘S’.
The word “Coding” is present from index ‘5’ to index ‘10’ in ‘S’.
The word “Code” is not present in ‘S’.
3
This is String
2
This String
Code Infy
3
C I F
coding
1
CodingNinjas
True True
True True False
False
Test case 1:
Here String ‘S’ is “This is String” and ‘wordList’ is [“This”, “String” ]
The word “This” is present from index ‘0’ to index ‘3’ in ‘S’.
The word “String” is present from index ‘8’ to index ‘13’’ in ‘S’.
Test case 2:
Here String ‘S’ is “Code Infy” and ‘wordList’ is [“C” “I” “F”]
The word “C” is present at index ‘0’ ’ in ‘S’.
The word “I” is present at index ‘5’ in ‘S’.
The word “F” is not present in ‘S’.
Test case 3:
Here String ‘S’ is “Coding” and ‘wordList’ is [“ CodingNinjas”]
The word “CodingNinjas” is not in ‘S’.
Iterate through all of the words in wordList, checking if each of them is contained in the ‘S’.
O(N*|S|*|W|), where ’N’ is the number of words in ‘wordList’, |S| is the length of string ‘S’, and |W| is the maximum length of words present in ‘wordList’.
Here, we will have three nested loops, and in the worst case the outermost loop runs ‘N’ time, and the middle loop runs |S| time and the innermost loop runs |W| times. This time complexity should be of order O(N*|S|*|W|).
O(N), where ’N’ is the number of words in ‘wordList’
The size of the result array is of order ‘N’.