`{"id":"8cc204a0-bbc9-4d3e-add8-b02c14f95992","name":"Rabbits In The Forest","description":"1. There are some rabbits in the forest and each rabbit has some color.\r\n2. Some(possibly all) rabbits are selected from them and they tell you about the number of other rabbits having the same color as them.\r\n3. You are given an array(arr) that contains the answers of all selected rabbits.\r\n4. You have to find the minimum number of rabbits that could be in the forest. ","inputFormat":"A number N\r\narr1\r\narr2.. N numbers","outputFormat":"A number representing the minimum number of rabbits in the forest.","constraints":"1 &lt;= N &lt;= 1000\r\n0 &lt;= arr[i] &lt;= 1000","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\nint solution(vector<int> arr) {\n //WRITE YOUR CODE HERE\n}\n\nint main()\n{\n int n;\n cin >> n;\n vector<int>arr(n, 0);\n for (int i = 0; i < n; i++)\n {\n cin >> arr[i];\n };\n\n cout << solution(arr);\n return 0;\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static int solution(int[] arr) {\r\n // write your code here\r\n \r\n return 0;\r\n }\r\n \r\n public static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tint[] arr = new int[n];\r\n\t\tfor(int i = 0 ; i < n; i++){\r\n\t\t\tarr[i] = scn.nextInt();\r\n\t\t}\r\n\t\tSystem.out.println(solution(arr));\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"5\r\n1 0 1 0 0","sampleOutput":"5\r\n","questionVideo":"https://www.youtube.com/embed/9mEUIdP4ytw?end=719","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"25668408-c439-41a2-a98e-1fc1dfc780b6","name":"Rabbits In The Forest","slug":"rabbits-in-the-forest","type":1}],"next":{"id":"4cb58c6c-6aca-4bee-9364-61a0f3bd97a7","name":"Rabbits In The Forest MCQ","type":0,"slug":"rabbits-in-the-forest-mcq"},"prev":{"id":"7a572e02-fa02-4cda-be0b-b9b19f001dcf","name":"Recurring Sequence In A Fraction","type":3,"slug":"recurring-sequence-in-a-fraction"}}}`

# Rabbits In The Forest

1. There are some rabbits in the forest and each rabbit has some color. 2. Some(possibly all) rabbits are selected from them and they tell you about the number of other rabbits having the same color as them. 3. You are given an array(arr) that contains the answers of all selected rabbits. 4. You have to find the minimum number of rabbits that could be in the forest.

`{"id":"8cc204a0-bbc9-4d3e-add8-b02c14f95992","name":"Rabbits In The Forest","description":"1. There are some rabbits in the forest and each rabbit has some color.\r\n2. Some(possibly all) rabbits are selected from them and they tell you about the number of other rabbits having the same color as them.\r\n3. You are given an array(arr) that contains the answers of all selected rabbits.\r\n4. You have to find the minimum number of rabbits that could be in the forest. ","inputFormat":"A number N\r\narr1\r\narr2.. N numbers","outputFormat":"A number representing the minimum number of rabbits in the forest.","constraints":"1 &lt;= N &lt;= 1000\r\n0 &lt;= arr[i] &lt;= 1000","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\nint solution(vector<int> arr) {\n //WRITE YOUR CODE HERE\n}\n\nint main()\n{\n int n;\n cin >> n;\n vector<int>arr(n, 0);\n for (int i = 0; i < n; i++)\n {\n cin >> arr[i];\n };\n\n cout << solution(arr);\n return 0;\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static int solution(int[] arr) {\r\n // write your code here\r\n \r\n return 0;\r\n }\r\n \r\n public static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tint[] arr = new int[n];\r\n\t\tfor(int i = 0 ; i < n; i++){\r\n\t\t\tarr[i] = scn.nextInt();\r\n\t\t}\r\n\t\tSystem.out.println(solution(arr));\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"5\r\n1 0 1 0 0","sampleOutput":"5\r\n","questionVideo":"https://www.youtube.com/embed/9mEUIdP4ytw?end=719","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"25668408-c439-41a2-a98e-1fc1dfc780b6","name":"Rabbits In The Forest","slug":"rabbits-in-the-forest","type":1}],"next":{"id":"4cb58c6c-6aca-4bee-9364-61a0f3bd97a7","name":"Rabbits In The Forest MCQ","type":0,"slug":"rabbits-in-the-forest-mcq"},"prev":{"id":"7a572e02-fa02-4cda-be0b-b9b19f001dcf","name":"Recurring Sequence In A Fraction","type":3,"slug":"recurring-sequence-in-a-fraction"}}}`

Editor

# Rabbits In The Forest

medium

1. There are some rabbits in the forest and each rabbit has some color. 2. Some(possibly all) rabbits are selected from them and they tell you about the number of other rabbits having the same color as them. 3. You are given an array(arr) that contains the answers of all selected rabbits. 4. You have to find the minimum number of rabbits that could be in the forest.

## Constraints

1 <= N <= 1000 0 <= arr[i] <= 1000

## Format

### Input

A number N arr1 arr2.. N numbers

### Output

A number representing the minimum number of rabbits in the forest.

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}5 1 0 1 0 0```

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}5 ```

Question Video

Discussions

Show Discussion

Related Resources