Pregunta de entrevista de Jane Street

graph question with regular expressions