C3 AI interview question

2 problems involving strings and graphs