TopCoder problem "FrequentPairs" used in TCHS07 Delta 2 (Division I Level One)



Problem Statement

    

Some pairs of letters appear frequently next to each other in words. For example, 'a' and 't' appear twice consecutively in the word "attach", and also twice in the word "tattoo". We don't care about the order in which they appear ("ta" or "at") or if the same letter is counted twice in the same word (thus we count two occurrences in "tat", for the same letters).

You will be given a String[] words, where each element is a single word. Find the pair of letters that appear next to each other most frequently, and return the number of times that pair appears in the entire list.

 

Definition

    
Class:FrequentPairs
Method:mostFrequent
Parameters:String[]
Returns:int
Method signature:int mostFrequent(String[] words)
(be sure your method is public)
    
 

Constraints

-words will contain between 1 and 50 elements, inclusive.
-Each element of words will contain between 2 and 50 lowercase letters ('a'-'z'), inclusive.
 

Examples

0)
    
{"attach", "tatoo"}
Returns: 4
1)
    
{"boo","boom","cool"}
Returns: 3
Here, 'b' and 'o' appear twice together. But double 'o' appears three times -- note the two letters don't need to be distinct.
2)
    
{"aaaaa"}
Returns: 4
Be careful to count each pair of 'a's only once!

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=7572

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10714&pm=7572

Writer:

ged

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

String Manipulation