Booking Holdings Interview Question

Graph traversal problem and some theory