Amazon Interview Question

Black hole with graph solution