Google interview question

technical interview - graph problem