Amazon interview question

Black hole with graph solution