Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Given a paragraph of text, write a program to find the first shortest sub - segment that contains each of the given k words at
Given a paragraph of text, write a program to find the first shortest subsegment that contains each of the given k words at least once. A segment is said to be shorter than other if it contains less number of words.
Ignore characters other than azAZ in the text. Comparison between the strings should be caseinsensitive.
If no subsegment is found, then the program should display NO SUBSEGMENT FOUND
Input format :
First line of the input contains the text.
Next line contains k the number of words to be searched.
Each of the next k lines contains a word.
Output format :
Print first shortest subsegment that contains given k words ignore special characters, numbers. If no subsegment is found, print NO SUBSEGMENT FOUND
Sample Input :
This is a test. This is a programming test. This is a programming test in any language.
this
a
test
programming
Sample Output :
a programming test This
Explanation :
Here, segment "a programming test. This" contains given four words. You have to print without special characters or numbers. So output is "a programming test This". Another segment "This is a programming test." also contains the given four words, but has more number of words.
Constraint :
Total number of characters in a paragraph will not be more than
k no of words in paragraph.
Each word length
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started