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.
/*
* Complete the 'cutTheSticks' function below.
*
* The function is expected to return an INTEGER_ARRAY.
* The function accepts INTEGER_ARRAY arr as parameter.
*/
public static List<Integer> cutTheSticks(List<Integer> arr) {
// Write your code here
int temp1 = 0 ;
int n = Collections.max(arr) ;
int [] temp = new int [n+1] ;
List<Integer> ans = new ArrayList<>();
ans.add(arr.size() - temp1 ) ;
for (int i =0 ; i < arr.size() ; i++) {
temp [arr.get(i)] ++ ;
}
for (int i =0 ; i < temp.length ; i++) {
if (temp[i] > 0) {
temp1+= temp[i];
if (temp1 == arr.size() ) {
return ans ;
}
ans.add(arr.size() - temp1 ) ;
}
}
return ans;
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Cut the sticks
You are viewing a single comment's thread. Return to all comments →
JAVA
class Result {
}