Visa Inc. Interview Question

Coding question on graphs and difficulty is medium