xlshi
BAN USER
Comments (4)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
-1
of 1 vote
What if sort the server and task first and assign the largest task to largest server, then add the smaller task to that server. The following code is the implementation of the algorithm above
public boolean arrange(int[] servers, int[] tasks){
Arrays.sort(servers);
Arrays.sort(tasks);
for(int i = servers.length - 1; i >= 0; i--){
for(int j = tasks.length - 1; j >= 0; j--){
if(tasks[j] <= servers[i]){
servers[i] -= tasks[j];
tasks[j] = 0;
}
}
}
for(int j = 0; j < tasks.length; j++){
if(tasks[j] > 0)
return false;
}
return true;
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
My solutions:
1) sort holes and mice
2) get the max difference between holes[i] and mice[i] 0<=i<holes.length
- xlshi September 14, 2014