Problem solving with programming: Minimum number of chages to make equal groups
Read full article from Problem solving with programming: Minimum number of chages to make equal groups
Given an array of numbers, how do we find the minimum number of changes(additions/deletions) to the elements so that each number in the array is same or equal.
For example given the array {1, 2, 3, 4}, the minimum number of changes are 3. i.e we can choose any of the four elements and make the other three elements equal to the chosen element.
Similarly given the array {56, 29, 112, 29}, the minimum number of changes to make is 2. We can choose 29 as the common element and change the other two elements.
http://comproguide.blogspot.in/2013/09/finding-most-occuring-element-mode-in.htmlwhile( t-- ){int n;cin >> n;vector<int> piles(n);int i;for( i = 0; i < n; i++ ){cin >> piles[i];}sort( piles.begin(), piles.end() );int maxCount = 1;int current = 1;for( i = 1; i < n; i++ ){if( piles[i] == piles[i-1] ){current++;}else{maxCount = max(current,maxCount);current = 1;}}maxCount = max(current,maxCount); // last timecout << n - maxCount << endl;}
Read full article from Problem solving with programming: Minimum number of chages to make equal groups