We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Here idea behind is
1. Sort shot's lower range so that if for any pleayer's upper range is less than lower range of a given shot then it will be lower for all the subsequent shot's lower range since that is sorted.
2. Sort player's lower range , so that if the shot's higher range is less than the given player's lower range then that means that shot's higher range will always be less than the subsequent player's lower range as that is sorted.
Here post excluding this we will count all the other scenarios.
Code :
public static int solve(List> shots, List> players) {
// Write your code here
int sum=0;
Collections.sort(shots,(a,b)-> {
if(a.get(0)>b.get(0)){
return 1;
}
else{
return -1;
}
});
Collections.sort(players,(a,b)->{
if(a.get(0)>b.get(0)){
return 1;
}
else{
return -1;
}
});
for(List player:players){
Mr. X and His Shots
You are viewing a single comment's thread. Return to all comments →
Java 7 solution
Java 7 Solution:
Here idea behind is 1. Sort shot's lower range so that if for any pleayer's upper range is less than lower range of a given shot then it will be lower for all the subsequent shot's lower range since that is sorted. 2. Sort player's lower range , so that if the shot's higher range is less than the given player's lower range then that means that shot's higher range will always be less than the subsequent player's lower range as that is sorted.
Here post excluding this we will count all the other scenarios.
Code :