Pergunta de entrevista da empresa TikTok

Traversing the graph to find if path exist for a given string