>>12140169>>12140186>>12140164>>12140137A solution would to build an associative array D as follows: iterate over all groups G consecutively (not nested), and for each element i in group G, add an entry (i: G) to D if i is not yet in D, otherwise append G to the value of key i.
Then, iterate over D and check if any key has values A,B and C. The runtime of this is 2{size(A)+size(B)+size(C)}. The runtime of cross-checking A and B is size(A)*size(B), which grows much quicker in the size of A and B.