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.
Be the first one to answer
Add answer anonymously...
Popular interview questions of Software Engineer
Top HR questions asked in Nvidia Software Engineer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app