I am trying to solve a algorithm problem in efficient way. Below is problem
I am going to explain this problem taking character as an example but in reality it could be anything (char, int, string, double, object etc). I doubt that should/would make any difference though
I have list of rows containing set of characters, let's say below are six lists
1 - A, B, C
2 - B, D
3 - E
4 - A
5 - F, B
6 - F, C
Now given a user input we want to find union of all subset of given input whose any combination can exactly match any of above rows. I will explain by giving example as below
Input Case 1 - A, C
Now in this case we have input as A, C so we will try to match if there was any row that contains exactly A, C and we won't find any. Next we will try to do find any row with A only and we find there is 1 and then we will try to find row for C only and we won't find so the output in this case would be A
Output - A
Input Case 2 - F, B, C
Now in this case we will see that there is no row containing only F, B, C so we will try combination i.e. F,B & we will there is row number 5 for it then F, C and we will see we have row number 6 for it. Considering all elements are covered now for this input we don't need to continue further but in case any element would have been left uncovered we will need to see other combinations as well (like B, C & then B & then C & then F)
Output - F, B, C
Input Case 3 - L, B, C
Now in this case we can see that there is no combination of above elements that can match any row hence output is Null
Output - Empty Set
Input Case 4 - F, B, D, C
Now in this case we see there is no row containing all elements so we try to see if there is some row matching F,B,D or B,D,C or F,C,D etc... and continuing similarly we will find output would be F, B, D, C (There is row for F,B & F, C & B, D which covers all elements)
Output - F, B, D, C
I am looking for an efficient way to get output. I can store data in any way (set/map/multiindex etc)