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.
Boggula Venkata Ajith Reddy
1mo
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
1mo
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
Help your peers!
Add answer anonymously...
Tata Group System Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter