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.
public static int toys(List<Integer> w) {
// Write your code here
Collections.sort(w);
int x;
int y;
int count=0;
int containerCount=0;
int k=0;
int i=0;
while(i<w.size()){
x=w.get(k);
y=x+4;
if(w.get(i)<=y){
i++;
count++;
}else{
containerCount++;
count=0;
k=w.indexOf(w.get(i));
}
}
return containerCount+1;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Priyanka and Toys
You are viewing a single comment's thread. Return to all comments →
Java