Pergunta de entrevista da empresa Microsoft

Given a string, how to find the shortest path in a grammar network that forms this string?