The problem statement does not specifically states what value to assign to neighbors with same productivity
(and does not disallow neighbor repetitions either). In the spirit of the problem, it makes sense to assign the same value. If there are neighbor developers with same productivity, then neither the priority queue based solution nor the last presented solution gives correct values.
The following was my approach:
static int[] fairBonus(int[] arr){
if (arr == null || arr.length == 0) return arr;
int[] ret = new int[arr.length];
for(int i = 0; i < arr.length; ++i){
ret[i] = 1;
}
for(int i = 1; i < arr.length; ++i){
if (arr[i-1] < arr[i]) ret[i] = ret[i-1]+1;
else if (arr[i-1] == arr[i]) ret[i] = ret[i-1];
}
for(int i = arr.length-2; i >= 0; --i){
int val = ret[i];
if (arr[i] > arr[i+1]) val = ret[i+1]+1;
else if (arr[i] == arr[i+1]) val = ret[i+1];
ret[i] = Math.max(ret[i], val);
}
return ret;
}