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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <set>

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<int> AB;
  set<int> BC;
  set<int> CA;
  set<int> 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. " <<endl;
  cout << " The max number of unique elements = " << maxSize << endl;

  return 0;
}


 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.