### Selecting Best Arrays

Supposing you have a 3 or more overlapping arrays (arrays having elements in common), and you wish to select 2 or more of the arrays with the maximum number of elements but less overlap as compared to the rest of the overlapping arrays.

Eg. A[4],B[6],C[5]. A+B contains 10 elements but say the overlapping element is 3, meaning it has 7 unique element. Also B+C=11 elements , but supposing it has 5 overlaps, it would mean it has only 6 unique elements. A+B+C=15. Supposing the overlaps are 11 then it means the unique elements are 4. Ect. So per the example, the best array options with most unique element would be A+B
Form pair-wise sets (a set by definition stores only unique elements). The set that has the largest size is your answer.
Last edited on
Abhishekm71, sorry i don't get you, can you please implement what you saying in code? C++ i mean
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960`` ``````#include #include using std::set; using std::cout; using std::endl; int main() { int A[4] = { 0, 1, 2, 3 }; int B[6] = { 2, 3, 4, 5, 5, 6 }; int C[5] = { 5, 6, 7, 8, 9 }; set AB; set BC; set CA; set ABC; AB.insert( A, A + 4 ); AB.insert( B, B + 6 ); BC.insert( B, B + 6 ); BC.insert( C, C+ 5 ); CA.insert( C, C + 5 ); CA.insert( A, A + 4 ); ABC.insert( A, A + 4 ); ABC.insert( B, B + 6 ); ABC.insert( C, C + 5 ); int maxSet = 0; size_t maxSize = AB.size(); if ( BC.size() > maxSize ) { maxSize = BC.size(); maxSet = 1; } if ( CA.size() > maxSize ) { maxSize = CA.size(); maxSet = 2; } if ( ABC.size() > maxSize ) { maxSize = ABC.size(); maxSet = 3; } cout << " Array Combination No. " << maxSet << " has MAX unique elements. " <

 ``` Array Combination No. 3 has MAX unique elements. The max number of unique elements = 10```

http://ideone.com/PVpWUM
Last edited on
Thanks so much, i think i get it now. You the best
Topic archived. No new replies allowed.