TopCoder problem "CalcButton" used in SRM 246 (Division I Level Two , Division II Level Three)



Problem Statement

    

You are developing a new software calculator. You decided to add a new feature - the three-digit button. Clicking on this button will add three digits into the edit field. This feature is for fast typing of common digit combinations. The problem is to figure out which digits should be placed on this button. You have prepared some statistical data - a long sequence of digits. You have decided that the button will be chosen to minimize the quantity of clicking required for typing this sequence.

You will be given a String[] sequence. The data is divided into several rows only for convenience. You can assume that this is a solid array (i.e. the first character in the i-th row is directly after the last character in the (i-1)-th row). You should return a three-character String containing the digits on the button. If there are several solutions you should return the one which appears first lexicographically.

 

Definition

    
Class:CalcButton
Method:getDigits
Parameters:String[]
Returns:String
Method signature:String getDigits(String[] sequence)
(be sure your method is public)
    
 

Constraints

-sequence will have between 1 and 50 elements, inclusive.
-Each element of sequence will contain between 1 and 50 characters, inclusive.
-Each element of sequence will contain only digits ('0'-'9').
 

Examples

0)
    
{"100002000"}
Returns: "000"
We can type the sequence in 5 clicks (the extra button is used twice)
1)
    
{"777777777"}
Returns: "777"
We can type the entire sequence in 3 clicks
2)
    
{"6503","210"}
Returns: "032"
A sequence can be divided into several rows.
3)
    
{"0993034","6","4137","45959935","25939","93993","0","9358333"}
Returns: "993"

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=7221&pm=4472

Writer:

Andrew_Lazarev

Testers:

PabloGilberto , lbackstrom , brett1479

Problem categories:

Brute Force