3493. Properties Graph Medium

@problem@discussion
#Array#Hash Table#Depth-First Search#Breadth-First Search#Union-Find#Graph Theory



1/**
2 * [3493] Properties Graph
3 *
4 * You are given a 2D integer array properties having dimensions n x m and an integer k.
5 * Define a function intersect(a, b) that returns the number of distinct integers common to both arrays a and b.
6 * Construct an undirected graph where each index i corresponds to properties[i]. There is an edge between node i and node j if and only if intersect(properties[i], properties[j]) >= k, where i and j are in the range [0, n - 1] and i != j.
7 * Return the number of connected components in the resulting graph.
8 *  
9 * <strong class="example">Example 1:
10 * <div class="example-block">
11 * Input: <span class="example-io">properties = [[1,2],[1,1],[3,4],[4,5],[5,6],[7,7]], k = 1</span>
12 * Output: <span class="example-io">3</span>
13 * Explanation:
14 * The graph formed has 3 connected components:
15 * <img height="171" src="https://assets.leetcode.com/uploads/2025/02/27/image.png" width="279" />
16 * </div>
17 * <strong class="example">Example 2:
18 * <div class="example-block">
19 * Input: <span class="example-io">properties = [[1,2,3],[2,3,4],[4,3,5]], k = 2</span>
20 * Output: <span class="example-io">1</span>
21 * Explanation:
22 * The graph formed has 1 connected component:
23 * <img alt="" src="https://assets.leetcode.com/uploads/2025/02/27/screenshot-from-2025-02-27-23-58-34.png" style="width: 219px; height: 171px;" />
24 * </div>
25 * <strong class="example">Example 3:
26 * <div class="example-block">
27 * Input: <span class="example-io">properties = [[1,1],[1,1]], k = 2</span>
28 * Output: <span class="example-io">2</span>
29 * Explanation:
30 * intersect(properties[0], properties[1]) = 1, which is less than k. This means there is no edge between properties[0] and properties[1] in the graph.
31 * </div>
32 *  
33 * Constraints:
34 * 
35 * 	1 <= n == properties.length <= 100
36 * 	1 <= m == properties[i].length <= 100
37 * 	1 <= properties[i][j] <= 100
38 * 	1 <= k <= m
39 * 
40 */
41pub struct Solution {}
42
43// problem: https://leetcode.com/problems/properties-graph/
44// discuss: https://leetcode.com/problems/properties-graph/discuss/?currentPage=1&orderBy=most_votes&query=
45
46// submission codes start here
47
48impl Solution {
49    pub fn number_of_components(properties: Vec<Vec<i32>>, k: i32) -> i32 {
50        0
51    }
52}
53
54// submission codes end
55
56#[cfg(test)]
57mod tests {
58    use super::*;
59
60    #[test]
61    fn test_3493() {
62    }
63}
64

Back
© 2026 bowen.ge All Rights Reserved.