Premium problem29. Is It a Valid Partition?

Medium Locked

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

B1∪⋯∪Bn=Ω,Bi∩Bj=∅;(i≠j)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.

Input

groups = [{1, 2}, {3, 4}]
sample_space = {1, 2, 3, 4}

Output

True

Premium problem

This one's part of Premium. Unlock the full Probability track plus every other premium problem on the site.

Implement solve(...)