public static int[] getMilestoneDays(int[] revenues, int[] milestones) {
int[] output = new int[milestones.length];
Arrays.fill(output, -1);
int sum = 0;
for (int i = 0; i < revenues.length; i++) {
revenues[i] += sum;
sum = revenues[i];
}
for (int i = 0; i < milestones.length; i++) {
int searchFor = milestones[i];
int low = 0;
int high = revenues.length - 1;
int mid = 0;
while (low <= high) {
mid = (high + low) / 2;
if (searchFor == revenues[mid]) {
output[i] = mid;
break;
} else if (searchFor < revenues[mid] && (mid - 1 < revenues.length && searchFor > revenues[mid - 1])) {
output[i] = mid - 1;
break;
} else if (searchFor < revenues[mid])
high = mid - 1;
else if (searchFor > revenues[mid] && (mid + 1 < revenues.length && searchFor < revenues[mid + 1])) {
output[i] = mid + 1;
break;
} else if (searchFor > revenues[mid])
low = mid + 1;
}
}
for (int i = 0; i < output.length; i++)
output[i]++;
return output;
}

### Like this:

Like Loading...

*Related*