Jane Street Interview Question

graph question with regular expressions