If a [i] is equal for m pieces different i, how do we get the number of equal pairs it gives rise to? (If m <2 there will be no pairs at all, if m = 2 there will be one pair, if m = 3 there will be three pairs, if m = 4 there will be the six pairs,… What will it be in general?)
int [] a = { 1, 2, 3, 1, 3, 1 };
I have used the following method but it doesn't give me full answer when it comes to figuring out the answer for m?
int pairs = 0;
int m = 0;
N = array.length
for (int i = 0; i < N; i++) {
for (int j = i+1; j < N; j++) {
if (array[i] == array[j])
pairs++;
}
return pairs;
}
It gives 3 as an output for pairs but an explanation of how to find out m will be appreciated!
Thanks in advance