Two Sigma Interview Question

The classic Friend circle problem