Pregunta de entrevista de TikTok

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