Back to problems

Non-connected People Pairs

Algorithm · Snapchat · Medium

Count Non-Friend Pairs There are n people in a social network, labeled from 0 to n - 1. The list connections describes direct friendships: each entry [a, b] means person a and person b are directly connected, and all friendships are mutual. If two people can reach each other through a chain of direct friendships, they belong to the same friend group. In graph terms, each friend group is a connected component. Return the number of unordered pairs (i, j) such that 0 <= i < j <…

Loading the rest of the question…