Given an array of arrays for example

[[“A”, “B”], [“A”, “B”, “D”, “C”], [“B”, “D”], [“B”, “C”, “F”, “E”],

[“C”, “F”], [“C”, “E”], [“G”]]

what would be a nice way of “merging” the items that seem to already be

contained in another array. e.g.

[“A”,“B”] and [“B”, “D”] are subsets of [“A”, “B”, “D”, “C”] I would

like to drop the subsets and be left with [“A”, “B”, “D”, “C”] only.

My approach was to use the set module in Ruby, and look for set

membership using a pairwise comparison.

I also thought maybe i should look for the largest set. and then check

whether the rest of the sets are subsets of this set. if they are, then

delete them.

However i thought a better solution, or strategy may already exist.

How would you accomplish this?