Two Sigma Interview Question

Friend circle question leetcode