Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Given two sentences, s and t, t is a subsequence of s if all of the words in toccur in the same order within
Given two sentences, s and t, t is a subsequence of s if all of the words in toccur in the same order within s. Words do not have to appear contiguously in s, but order must be maintained. For example, given the sentence "I like cheese", one example of a subsequence would be "I cheese". In this challenge, you will be given two sentences, s and t. It is guaranteed that string tis a subsequence of string s. When reading string s from left to right, locate the first occurrence of subsequence t. Remove this subsequence and return the remaining elements of string s in order. Example: s = I like eating cheese do you like cheese t = like cheese Return: I eating do you like cheese Helpful Note: Be sure to always take the first occurrence of an element if it appears multiple times in a subsequence. For example: s = I like soft cheese and hard cheese yum t = like cheese yum Notice that there are two subsequences in string s containing t I like soft cheese and hard cheese yum I like soft cheese and hard cheese yum The correct return will remove the the 4th word, not the 7th word, returning "I soft and hard cheese" rather than "I soft cheese and hard". Function Description Complete the function missingWords in the editor below. It must return the list of words in s that remain after removing the first occurrence of subsequence t with each returned word on its own line. missingWords has the following parameter(s): s: a sentence of space-separated words t: a sentence of space-separated words Constraints Strings s and t consist of English alphabetic letters (i.e., a-z and A-Z) and spaces only. 1 /t/s/s/ 106 1 length of any word in sorts 15 It is guaranteed that string tis a subsequence of string s. Input Format for Custom Testing Input from stdin will be processed as follows and passed to the function. The first line contains a string s. The first line contains a string t # Complete the missingWords function below. def missingWords (s, t): if __name__ == '__main__': fptr = open(os.environ['OUTPUT_PATH'], 'w') s=input() t = input() res missingWords (s, t) fptr.write(' '.join(res)) fptr.write(' ') fptr.close()
Step by Step Solution
★★★★★
3.34 Rating (154 Votes )
There are 3 Steps involved in it
Step: 1
Complete Code in Python def missingWordss t This function removes the first occurrence of subsequence t from sentence s and returns the remaining word...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