Problem Statement |
| | There is a number of people in a room, and each of them wears a hat which is either black or white.
Every person counts the number of other people wearing white hats. You are given a int[] count, the i-th element of which is the number counted by the i-th person. Return the total number of people wearing white hats, or -1 if count doesn't correspond to a valid situation.
|
| |
Definition |
| | | Class: | WhiteHats | | Method: | whiteNumber | | Parameters: | int[] | | Returns: | int | | Method signature: | int whiteNumber(int[] count) | | (be sure your method is public) |
|
| |
|
| |
Constraints |
| - | count will contain between 2 and 50 elements, inclusive. |
| - | Each element of count will be between 0 and 50, inclusive. |
| |
Examples |
| 0) | |
| | | Returns: 2 | | The first person wears a black hat and sees two people wearing white hats. Each person wearing a white hat sees only one other white hat in the room. |
|
|
| 1) | |
| | | Returns: 3 | | Everyone wears a white hat here. |
|
|
| 2) | |
| | |
| 3) | |
| | |
| 4) | |
| | | Returns: -1 | | Now that's interesting. There are only two people in the room, yet each of them counted 10 others. |
|
|