n objects carries exactly m tags, given as rows tags[i] (a row may repeat a tag). You also get an integer k.
Two different objects are directly linked when they have at least k **distinct** tags in common. Links chain together: if a is linked to b and b to c, all three belong to the same group.
Return the number of groups.tags=[[1, 2, 3], [3, 4, 5], [6, 7, 8], [8, 9, 6]], k=1 → 2
Rows 0 and 1 share tag 3, rows 2 and 3 share tags 6 and 8. The two pairs have nothing in common, so there are two groups.
tags=[[5, 5, 1], [5, 1, 1]], k=2 → 1
There are two distinct common tags, 5 and 1. Repeats do not count twice, but two is enough, so there is one group.
tags=[[4, 4], [4, 4]], k=2 → 2
Only one distinct tag (4) is shared and at least two are needed, so each row is on its own.
tags=[[1, 2, 3], [3, 4, 5], [6, 7, 8], [8, 9, 6]], k=1
2
Run checks the first 3 tests in your browser. Submit checks all 95 tests on the server, hidden ones included.