I'm going to assume that the words are space delimited so that words
can't overlap. Use a trie to identify words. Then keep a counter for
each word, an "attempt" counter and a "words in this attempt" counter.
Start the word counter array with all zeroes and the attempt counter
at one.

Every time you find a word which is not in the list, increment the
attempt counter and set the "words in attempt" to zero. When you find
a word in the list, if "words in attempt" is zero, save the index of
that word. Then compare that word's counter to the attempt counter. If
they don't match, set the word's counter to the attempt counter and
increment "words in this attempt". I'm not sure what the rule is about
words on the list occurring twice. If that is allowed, ignore words
where the counters match. Otherwise treat them like words not on the
list. When "words in attempt" equals n, the saved index is the result.

Don



On Apr 18, 12:04 am, marti <amritsa...@gmail.com> wrote:
> Given a list of words wordlist on 1st line (no of words <= 100) and a
> string qstr of len <= 1 million on 2nd line, print the index at qstr where
> a continuous substring exists that contains all the given words in wordlist.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to