Google Interview Question

a variation of string matching problem