Leetcode in Java && Oracle
424 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2023-01-04_06-06-40.png
39.5 KB
Runtime11 msBeats98.9%
Memory51.3 MBBeats99.48

#N2244. Minimum Rounds to Complete All Tasks
problem link
#solution
class Solution {
public int minimumRounds(int[] tasks) {
Arrays.sort(tasks);
int l=tasks.length;
if(l>1 && tasks[l-2]!=tasks[l-1]) return -1;
int r=0, type=tasks[0], count=0;


for(int i=0; i<l; i++){
if(type==tasks[i]) count++;
if(type!=tasks[i] || i==l-1){
type=tasks[i];
if(count==1) return -1;
else r+=count/3 + (count%3+count%3%2)/2;
count=1;
}
}
return r;
}
}
👍32