TopcoderArchiveVisit Topcoder
Archive20 Feb 2003
TCCC '03 W/MW Regional

LongestRun

Problem statement, definition, constraints, and public examples.

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

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