valid segments 1, C/C++ Programming

Consider text comprised of sentences and sentences comprised of words. Words in a sentence will be space delimited. Given a text and K strings, task is to find out the number valid segments whose length lies in the range [lb, ub].

A segment is said to be valid if

It contains all the K-strings It should start and end with any one of the K-strings