Check Word Presence in String
Given a string S
and a list wordList
containing N
distinct words, determine if each word in wordList
is present in S
. Return a boolean array where the value at index 'i' indicates the presence of Wi
in S
.
Input:
The first line contains an integer ‘T’, the number of test cases.
The following 3*T lines represent the test cases:
The first line of each test case provides the string ‘S’.
The second line provides an integer ‘N’, the number of words in ‘wordList’.
The third line provides ‘N’ space-separated strings indicating the words in ‘wordList’.
Output:
For each test case, output a boolean array indicating if each word in ‘wordList’ is present in ‘S’.
Example:
Input:
2
hello world
3
hello world Code
Programming is fun
2
fun Code
Output:
[True, True, False]
[True, False]
Constraints:
- 1 <= T <= 50
- 1 <= |S| <= 10^3
- 1 <= N <= 10^3
- 1 <= |W| <= 10
Note:
- String 'S' includes lowercase, uppercase alphabets, and spaces.
- String ‘Wi’ consists of lowercase and uppercase alphabets only.
- The presence of ‘Wi’ is case sensitive.
- Do not use built-in string-matching methods.
- Return the boolean array without printing it.

AnswerBot
4mo
Given a string and a list of words, determine if each word in the list is present in the string and return a boolean array indicating their presence.
Iterate through each word in the word list and chec...read more
Boggula Venkata Ajith Reddy
6mo
Check If Given Words Are Present In A String 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 'wordL...read more
Anonymous
6mo
Check If Given Words Are Present In A String 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 'wordL...read more
Add answer anonymously...
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

