TopCoder problem "StringOfNumbers" used in TCHS07 Beta 3 (Division I Level Two)



Problem Statement

    

All numbers between 1 and N, inclusive, in ascending order and with no spaces in between, were written on a piece of paper. Afterwards, some of the digits were erased. You will be given a String[] leftDigits. Concatenate all the elements of leftDigits, and the resulting string will contain the digits that are left on the piece of paper, in order. Return the lowest possible value that N could have had.

 

Definition

    
Class:StringOfNumbers
Method:getLeastN
Parameters:String[]
Returns:int
Method signature:int getLeastN(String[] leftDigits)
(be sure your method is public)
    
 

Constraints

-leftDigits will contain between 1 and 50 elements, inclusive.
-Each element of leftDigits will contain between 1 and 50 characters, inclusive.
-Each character in leftDigits will be a digit ('0'-'9').
 

Examples

0)
    
{"1234"}
Returns: 4
N could have been 4, in which case no digits were erased.
1)
    
{"234092"}
Returns: 20
The least value that N can take in this case is 20: 2, 3 and 4 come from the corresponding numbers, 0 comes from 10, 9 from 19 and 2 is the most significant digit of 20.
2)
    
{"000000000000000000000000000", "0000000000000000000000", "0000000000000000000000"}
Returns: 400
3)
    
{"3450298340230498203948023", "3490924098203984203948", "3294792934790209"}
Returns: 279

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10713&pm=7528

Writer:

_efer_

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Greedy, String Manipulation