TopCoder problem "RepresentNumber" used in Round 1 (Division I Level Three)



Problem Statement

    

You have some digits, and you want to use one or more of them to create the largest possible number. The number must have no extra leading zeroes, and no two adjacent digits can be the same. For example, "0121" and "2110" are not valid numbers.

You are given a int[] digits containing exactly 10 elements. The i-th element (0-based) is the number of digit i that you have. Return a String denoting the maximum valid number you can create.

 

Definition

    
Class:RepresentNumber
Method:maximumNumber
Parameters:int[]
Returns:String
Method signature:String maximumNumber(int[] digits)
(be sure your method is public)
    
 

Constraints

-digits will contain exactly 10 elements.
-Each element of digits will be between 0 and 50, inclusive.
-The sum of the elements of digits will be between 1 and 50, inclusive.
 

Examples

0)
    
{3,0,0,0,0,0,0,0,0,0}
Returns: "0"
1)
    
{4,1,2,0,0,0,0,0,0,0}
Returns: "202010"
2)
    
{4,1,8,0,0,0,0,0,0,0}
Returns: "21202020202"
You can't use all the '2' digits.
3)
    
{0,1,4,4,1,4,0,2,2,0}
Returns: "878754535352323212"
4)
    
{0,3,3,2,4,4,3,4,1,4}
Returns: "9897979767656545454343212121"

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=12212&pm=8770

Writer:

stone

Testers:

PabloGilberto , Olexiy , ivan_metelsky

Problem categories:

Greedy