Class Solution
-
- All Implemented Interfaces:
public final class Solution3493 - Properties Graph.
Medium
You are given a 2D integer array
propertieshaving dimensionsn x mand an integerk.Define a function
intersect(a, b)that returns the number of distinct integers common to both arraysaandb.Construct an undirected graph where each index
icorresponds toproperties[i]. There is an edge between nodeiand nodejif and only ifintersect(properties[i], properties[j]) >= k, whereiandjare in the range[0, n - 1]andi != j.Return the number of connected components in the resulting graph.
Example 1:
Input: properties = [1,2,1,1,3,4,4,5,5,6,7,7], k = 1
Output: 3
Explanation:
The graph formed has 3 connected components:
Example 2:
Input: properties = [1,2,3,2,3,4,4,3,5], k = 2
Output: 1
Explanation:
The graph formed has 1 connected component:
Example 3:
Input: properties = [1,1,1,1], k = 2
Output: 2
Explanation:
intersect(properties[0], properties[1]) = 1, which is less thank. This means there is no edge betweenproperties[0]andproperties[1]in the graph.Constraints:
1 <= n == properties.length <= 1001 <= m == properties[i].length <= 1001 <= properties[i][j] <= 1001 <= k <= m