1

I have a list of lists. I want to count the number of independent lists. By independent I mean that if a list has at least 1 number that is in another list then it is not independent.

If 2 list share a number then they count as 1 independent list. If 3 list share a number then it also counts as 1 independent list and so on.

Example 1

Input = [[1,2],[2,3],[4,5]]
Output = 2 
## ([4,5] and since [1,2] and [2,3] intersect, it counts as 1)

Example 2

Input = [[3004,2002],[2001,3000],[4500,5000,3004]]
Output = 2 
## ([2001,3000] and since [4500,5000,3004] and [3004,2002] intersect, it counts as 1)
Moo
  • 41
  • 1
  • 3
  • 1
    This is an interesting problem, have you written anything so far to try to solve it? – C_Z_ May 20 '21 at 01:05
  • 1
    Can a list have duplicate elements? Is the length of the lists arbitrary? This would be important if you are looking for an efficient solution. – Gray_Rhino May 20 '21 at 01:08

0 Answers0