Given answers from rabbits about how many other rabbits share their color, compute the minimum possible total number of rabbits in the forest.
Each rabbit reports a number x, meaning: there are exactly x other rabbits in the forest with the same color as this rabbit.
You are given an array answers where answers[i] is the report from the i-th rabbit. Your task is to determine the minimum possible number of rabbits that could be in the forest while still being consistent with all reports.
A rabbit reporting x implies it belongs to a color group of size x + 1. Multiple rabbits may give the same report, and rabbits with the same report may belong to different color groups.
Return the minimum total number of rabbits that can satisfy all answers.
answers
answers[i] >= 01 <= answers.lengthanswers[i] are non-negative integersx corresponds to groups of size x + 1Example 1
Input
answers = [1, 1, 2]
Output
5
Explanation
Two rabbits say there is 1 other rabbit of the same color, so they can form one group of size 2. One rabbit says there are 2 others of the same color, so it needs a group of size 3. Total minimum = 2 + 3 = 5.
Example 2
Input
answers = [10, 10, 10]
Output
11
Explanation
Each rabbit says there are 10 others of the same color, so all three can be placed in one color group of size 11. The minimum total is 11.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.