Problem Statement |
| Some sharks are having dinner and they are eating each other. For every shark we know its size, speed and intelligence (measured in positive integers). Shark A can eat shark B if and only if A's size, speed and intelligence are all greater than or equal to B's. Due to digestive restrictions, each shark can eat at most two other sharks.
Given int[] size, int[] speed and int[] intelligence, return the minimum number of sharks that will survive. |
|
Definition |
| Class: | SharksDinner | Method: | minSurvivors | Parameters: | int[], int[], int[] | Returns: | int | Method signature: | int minSurvivors(int[] size, int[] speed, int[] intelligence) | (be sure your method is public) |
|
|
|
|
Constraints |
- | size, speed and intelligence will contain the same number of elements. |
- | size, speed and intelligence will each contain between 1 and 50 elements, inclusive. |
- | Each element of size, speed and intelligence will be between 1 and 2,000,000,000, inclusive. |
|
Examples |
0) | |
| { 1, 4, 3 } | { 2, 3, 1 } | { 1, 5, 2 } |
| Returns: 1 | Shark 1 eats sharks 0 and 2 so we get 1 survivor. |
|
|
1) | |
| { 4, 10, 5, 8, 8 } | { 5, 10, 7, 7, 10 } | { 5, 8, 10, 7, 3 } |
| Returns: 2 | Shark 2 eats shark 0, and shark 1 eats sharks 3 and 4. |
|
|
2) | |
| { 1, 2, 3, 4, 100 } | { 4, 3, 2, 1, 100 } | { 2, 4, 1, 3, 100 } |
| Returns: 3 | The big shark eats two of the smaller sharks and is not hungry anymore, so the other two of the smaller sharks are lucky (and they cannot eat each other). |
|
|
3) | |
| { 4, 4, 4, 4 } | { 3, 3, 3, 3 } | { 8, 8, 8, 8 } |
| Returns: 1 | Sharks with the same level of speed, size and intelligence can eat each other. |
|
|