29. Is It a Valid Partition?

Medium

The law of total probability only holds when the groups form a partition: they must cover the whole sample space and must not overlap.

B1Bn=Ω,BiBj=;(ij)B_1 \cup \cdots \cup B_n = \Omega, \qquad B_i \cap B_j = \varnothing ; (i \neq j)

groups is a list of sets. Return True only if both conditions hold. An empty group is allowed; it breaks neither rule.

solve([{1,2}, {3,4}], {1,2,3,4})     ->  True
solve([{1,2}, {2,3}], {1,2,3})       ->  False    # overlap
solve([{1,2}], {1,2,3})              ->  False    # does not cover

Sign in to write and run your own code.

Implement solve(...)