Rabbits In Forest


i think there is a solution based on sorted array:
class Solution { public int numRabbits(int[] answers) { if(answers.length==0)return 0; java.util.Arrays.sort(answers); int pre=answers[0],cur = pre,sum=0; for(int i=1;i<=answers.length;i++){ if(i==answers.length){ sum+=pre+1; }else{ if(answers[i]==pre){ if(cur<0){ cur = answers[i]; sum+=pre+1; } }else{ sum+=pre+1; cur = answers[i]; } pre = answers[i]; } } return sum; } }

@dejokz floorMod(k, m) is just the nonnegative value of k % m.
If there are say 2 rabbits that say 9, there are 10 total in that group, so we want 2 % 10 = 8 more.