Computer Science, asked by aseemalatheef, 10 months ago

ZEE-BEE Company has the list of appraisal ratings for their employees. Write a java program to find the maximum difference between any pair of appraisal rating.The program should display the first occurrence of index positions of the pair that has the maximum difference (Assume absolute difference between pairs)

If the array elements or if the size is negative display as “Invalid”.

Answers

Answered by dhruvinkachhadia
4

static int maxDifference(int[] a) {

//test array size

if (a.length < 1 || a.length > 1_000_000) return -1;

int[] oldArr = Arrays.copyOf(a, a.length);

Arrays.sort(a);

int max = a[a.length - 1];

if (max > 1_000_000 || a[0] < -1_000_000) return -1; to

int min = max;

for (int i = 0; i < oldArr.length; i++) {

if (oldArr[i] < max) {

min = Math.min(min, oldArr[i]);

}

if (oldArr[i] == max) break;

}

int result = min == max ? -1 : max - min;

return result;

}

Kindly mark it as Brainliest if find it useful. Thank you!

Similar questions