Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com

Check if the Word is present in Sentence or not

Easy
0/40
Average time to solve is 15m
25 upvotes
Asked in companies
AmazonWalmartIntuit

Problem statement

You have been given a sentence ‘S’ in the form of a string and a word ‘W’, you need to find whether the word is present in the given sentence or not. The word must be present as a complete string in the sentence and not a substring of some other word.

Note:

1. All the characters in the string and the word are in lowercase.
2. Length of the sentences and the words will always be greater than zero.
3. Words in the sentence will be separated by spaces.
Detailed explanation ( Input/output format, Notes, Images )
Sample Input 1:
2
abaa ba
abaa
coding is fun
not
Sample Output 1:
Yes
No
Explanation for Sample Input 1:
For the first input,  “abaa” is present in the sentence.
For the second input, “not” is not present in the sentence.
Sample Input 2:
2
the quick brown fox
brown
welcome to coding ninjas
ninja
Sample Output 2:
Yes
No
Explanation for Sample Input 2:
For the first input, “brown” is present in the sentence.
For the second input, the word “ninja” is not present in the sentence.
Full screen
Console