Two Sigma interview question

The classic Friend circle problem