TopcoderArchive
Archive
Algorithm problem

RepresentNumber

Problem statement, definition, constraints, and public examples.

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

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