TopCoder problem "LongestRun" used in TCCC '03 W/MW Regional (Division I Level Two)



Problem Statement

    Given a collection of n strings, there are n! ways to concatenate them into a single string. Create a class LongestRun that contains method runLength that takes a String[] collection as input and returns the length of the longest run that can be formed by concatenating the strings.

A run is a sequence of adjacent identical characters. For example, "CACAAABBQ" contains a run of 2 B's and a run of 3 A's (as well as four other runs of length 1).

 

Definition

    
Class:LongestRun
Method:runLength
Parameters:String[]
Returns:int
Method signature:int runLength(String[] collection)
(be sure your method is public)
    
 

Constraints

-collection contains between 1 and 50 elements inclusive
-each element of collection contains between 1 and 50 characters inclusive
-each element of collection contains only uppercase letters, 'A'-'Z'
 

Examples

0)
    
{"ABC", "CBBB", "CC", "ABCDEFG"}
Returns: 4
We can get a run of 4 'C's by concatenating as follows: "ABC" + "CC" + "CBBB" + "ABCDEFG" -> "ABCCCCBBBABCDEFG"
1)
    
{"ABC", "CBBBC","ABCDEFG", "AD", "AE", "AF"}
Returns: 3
Any concatenation of these will have a run of 3 'B's
2)
    
{"GOOD","DOG","EGG","DO","GIGABYTE","OOO","G","G"}
Returns: 5
3)
    
{"AAABBBBAAA","BAABBBBAB"}
Returns: 4
4)
    
{"AAABBBBAAA","AABBBBA"}
Returns: 5

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=4464&pm=1328

Writer:

dgoodman

Testers:

lbackstrom , brett1479

Problem categories:

String Manipulation