Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A sub-word is a possibly non-contiguous sub-sequence of characters in a string which is also recognizably a word. Non- contiguous means the letters don't have

A sub-word is a possibly non-contiguous sub-sequence of characters in a string which is also recognizably a word. Non- contiguous means the letters don't have to appear next to each other. Sub-sequence means the letters are in the same order as found in the original string For example, the string sfponrtq contains several sub- words: for, port, and or are some. Note that the sub-sequence property means that prom is not a valid sub-word, since the letters in pron do not appear in sequence in sfponrtq. The longest sub-word in sfponrtq is sport In this problem you will be given a string and a vector of valid words. Your job is to find the length of the longest valid word that appears as a sub-word of the given string. If no valid words are sub-words of the input, then you should return 0

Notes and Constraints words contains between 0 and 50 words input will be between 1 and 50 characters in length All strings contain only lowercase, alphabetic characters

Example:s

1. input "sfponrtq" words "and, "is "for", "hello" Returns:3 In this dictionary, only "for" is a sub-word of the input.

2. inputsfponr tq" words ("or, sport", "port",for"fort "pot""sot" Returns: 5 All of the words are sub-words of the input, but "sport" is the longest.

3. supercalifragilisticexpialidocious" ( "sup, "super"superficial, "supercilious", s words Returns:12 Here, "supercilious" is the longest valid word input"xyz" words- {"a", "b", "c", "d") Returns: 0 There are no valid sub-words.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

To solve the problem of finding the length of the longest valid word that appears as a subword in the given string we can break down the solution into ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Algorithm Design And Applications

Authors: Michael T. Goodrich, Roberto Tamassia

1st Edition

1118335910, 978-1118335918

More Books

Students also viewed these Programming questions

Question

Eliminate street slang.

Answered: 1 week ago