-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlargestComponent.txt
More file actions
46 lines (45 loc) · 800 Bytes
/
largestComponent.txt
File metadata and controls
46 lines (45 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
largest component
Write a function, largestComponent, that takes in the adjacency list of an undirected graph. The function should return the size of the largest connected component in the graph.
test_00:
largestComponent({
0: ['8', '1', '5'],
1: ['0'],
5: ['0', '8'],
8: ['0', '5'],
2: ['3', '4'],
3: ['2', '4'],
4: ['3', '2']
}); // -> 4
test_01:
largestComponent({
1: ['2'],
2: ['1','8'],
6: ['7'],
9: ['8'],
7: ['6', '8'],
8: ['9', '7', '2']
}); // -> 6
test_02:
largestComponent({
3: [],
4: ['6'],
6: ['4', '5', '7', '8'],
8: ['6'],
7: ['6'],
5: ['6'],
1: ['2'],
2: ['1']
}); // -> 5
test_03:
largestComponent({}); // -> 0
test_04:
largestComponent({
0: ['4','7'],
1: [],
2: [],
3: ['6'],
4: ['0'],
6: ['3'],
7: ['0'],
8: []
}); // -> 3