public class lc846 {
public boolean isNStraightHand(int[] hand, int groupSize) {
TreeMap<Integer,Integer> count=new TreeMap();
for (int i : hand) {
if(count.containsKey(i)==false){
count.put(i,1);
}else{
count.replace(i,count.get(i)+1);
}
}
while (count.size()>0){
int begin=count.firstKey();
for(int i=begin;i<=begin+groupSize-1;i++){
if(count.containsKey(i)==true){
if(count.get(i)==1) count.remove(i);
else count.replace(i,count.get(i)-1);
}else return false;
}
}
return true;
}
}