Skip to content

Instantly share code, notes, and snippets.

@cloudbank
Last active October 6, 2018 02:40
Show Gist options
  • Save cloudbank/1d4bfd4c17479161ad44333aada00eb4 to your computer and use it in GitHub Desktop.
Save cloudbank/1d4bfd4c17479161ad44333aada00eb4 to your computer and use it in GitHub Desktop.
determine the salary cap given a target and list of salaries (unsorted)
public int salaryCap(int[] salaries, int target) {
int a = target / salaries.length;
int sum = 0, count=0;
for (int s: salaries) {
if (s <= a) {
sum += s;
} else {
count++;
}
}
return ((target - sum) / ((salaries.length) - (count)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment