import java.util.OptionalInt;
class EqualPairCounter {
int numberOfEqualPairsLinearWithExtraArrayAndStreams(int[] input) {
int max = input[0];
int min = input[0];
for (int v : input) {
}
int shift = min;
int[] countArr = new int[max - min + 1];
for (int v : input) {
int countIdx = v - shift;
countArr[countIdx]++;
}
OptionalInt res =
Arrays.
stream(countArr
) .parallel()
.filter(count -> count > 1)
.map(n -> (n - 1) * n / 2)
return res.orElse(0);
}
public static void main
(String[] args
) { int[] input = {1, 2, 4, 1, 2, 1, 2, -3, 4, 5, 1, 2, 4, 5, 1, -5, 2 ,5, 6, 7, -3, 7, 8, 2, 1, 2, -3, 4, 5};
int pairCount = new EqualPairCounter().numberOfEqualPairsLinearWithExtraArrayAndStreams(input);
System.
out.
println("Res: " + pairCount
);
// => 52 }
}