Connection Status:
Competition Arena > LongestRun
TCCC '03 W/MW Regional · 2003-02-20 · by dgoodman · String Manipulation
Class Name: LongestRun
Return Type: int
Method Name: runLength
Arg Types: (vector<string>)
Problem Statement

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).

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)
{"AABBBAAAA"}
Returns: 4

Submissions are judged against all 44 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class LongestRun with a public method int runLength(vector<string> collection) · 44 test cases · 2 s / 256 MB per case

Submitting as anonymous