Google interview question

a variation of string matching problem