Tap here to switch tabs
Problem
Submissions

Problem: Rabbits in Forest

med
30 min
Try to solve the Rabbits in Forest problem.

Statement

You are given an integer array answers where each element represents a rabbit’s response to the question: how many other rabbits in the forest have the same color as you. Specifically, if answers[i] = k, then that rabbit claims there are exactly kk other rabbits with its color.

Assuming every rabbit in answers answered truthfully, return the minimum possible total number of rabbits that could be in the forest, including rabbits that did not provide an answer.

Note: Rabbits that share the same color must have answers that are mutually consistent with the size of their color group.

Constraints:

  • 1≤1 \leq answers.length ≤1000\leq 1000

  • 0≤0 \leq answers[i] <1000< 1000

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Rabbits in Forest

med
30 min
Try to solve the Rabbits in Forest problem.

Statement

You are given an integer array answers where each element represents a rabbit’s response to the question: how many other rabbits in the forest have the same color as you. Specifically, if answers[i] = k, then that rabbit claims there are exactly kk other rabbits with its color.

Assuming every rabbit in answers answered truthfully, return the minimum possible total number of rabbits that could be in the forest, including rabbits that did not provide an answer.

Note: Rabbits that share the same color must have answers that are mutually consistent with the size of their color group.

Constraints:

  • 1≤1 \leq answers.length ≤1000\leq 1000

  • 0≤0 \leq answers[i] <1000< 1000