TopcoderArchive
Archive
Algorithm problem

StringOfNumbers

Problem statement, definition, constraints, and public examples.

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

  1. {"1234"}
    Returns: 4
    N could have been 4, in which case no digits were erased.
  2. {"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.
  3. {"000000000000000000000000000", "0000000000000000000000", "0000000000000000000000"}
    Returns: 400
  4. {"3450298340230498203948023", "3490924098203984203948", "3294792934790209"}
    Returns: 279
Back to all problems