PROBLEM STATEMENT
Bob is fumbling around in his sock drawer trying to find two socks that match.
The light in his room does not work so he decides to take some of the socks
into the next room and see if he has found a pair. You are to create a class
Socks with a method guarantee that returns the minimum number of socks that he
must take in order to guarantee a match. If Bob's sock drawer does not contain
any matching pairs, your method should return -1.
Each sock will be described by a non-empty string with a maximum length of 20
(a length of 1 to 20 inclusive). The string will contain only lower-case
letters (a-z inclusive) and spaces. Two socks are considered to match only if
their descriptions match exactly (for example, "blue" matches "blue" but
"white" does not match "white ").
DEFINITION
Class: Socks
Parameters: String[]
Returns: int
Method signature (be sure your method is public): int guarantee(String[] socks);
INPUT CONSTRAINTS
TopCoder will ensure that all input constraints are met.
- The input parameter socks will contain between 1 and 50 elements (inclusive).
- Each element of socks will be a string of length 1 to 20 (inclusive).
- Each element of socks will contain only lower-case letters (a-z) and spaces.
EXAMPLES
If socks={"tube", "tube", "tube", "dress", "dress"} there are two types of
socks (tube socks and dress socks). It is possible for Bob to take two socks
from the drawer without getting a match (one tube and one dress), but if he
takes three socks he must have at least two of a kind, so the method returns 3.
If socks={"wool", "cotton", "nylon"} then even if he takes all of the socks in
the drawer Bob still won't have a matching pair, so the method returns -1.
If socks={"striped green", "blue", "black", "white", "blue", "white", "striped
green"}, then the method returns 5.
If socks={"one hole", "one hole"}, then the method returns 2.