You are given a 2D integer array
properties
having dimensionsn x m
and an integerk
.Define a function
intersect(a, b)
that returns the number of distinct integers common to both arraysa
andb
.Construct an undirected graph where each index
i
corresponds toproperties[i]
. There is an edge between nodei
and nodej
if and only ifintersect(properties[i], properties[j]) >= k
, wherei
andj
are in the range[0, n - 1]
andi != j
.Return the number of connected components in the resulting graph.
c++
1 | class Solution { |