PROBLEM STATEMENT
Create a method that takes a string and counts the number of unique letter
pairs contained within the string. A letter pair is defined as any two adjacent
letters appearing in the string. The order of the letters does not matter. For
example, the pair "ah" is the same pair as the pair "ha". Letter pairs do not
contain space characters.
Given the input string, "and toto too", (the double quotes are not part of the
string), there are seven adjacent pairs of letters to consider: "an", "nd",
"to", "ot", "to", "to", "oo". Of these, "to" appears twice, and the pair "ot"
has the same letters as the pair "to". Thus, there are only four unique pairs:
"an", "nd", "to", "oo". (Note that the pair "to" could have been written as the
pair "ot" since the order of the characters in a pair is not significant.)
DEFINITION
Class Name: LetterPairs
Method Name: uniquePairs
Parameters: String
Returns: int
Method signature (be sure your method is public): int uniquePairs(String text);
TopCoder will ensure the following:
- text is from 0 to 50 characters in length inclusive
- text consists only of the lowercase letters a through z and the space
character
EXAMPLES
E1: uniquePairs("a") ==> 0
E2: uniquePairs("aha") ==> 1
E3: uniquePairs("xyzzy") ==> 3
E4: uniquePairs("and toto too") ==> 4
E5: uniquePairs("a hollow voice says plugh") ==> 15
E6: uniquePairs("another topcoder contest") ==> 15
E7: uniquePairs("the quick brown fox jumped over the lazy dog") ==> 25