TopCoder problem "SequenceOfNumbers" used in SRM 255 (Division II Level One)



Problem Statement

    

It is a common mistake to sort numbers as strings. For example, a sorted sequence like {"1", "174", "23", "578", "71", "9"} is not correctly sorted if its elements are interpreted as numbers rather than strings.

You will be given a String[] sequence that is sorted in non-descending order using string comparison. Return this sequence sorted in non-descending order using numerical comparison instead.

 

Definition

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

Constraints

-sequence will contain between 2 and 50 elements inclusive.
-Each element of sequence will contain between 1 and 9 characters inclusive.
-Each element of sequence will consist of only digits ('0'-'9').
-Each element of sequence will not start with a '0' digit.
-sequence will be ordered lexicographically.
 

Examples

0)
    
{"1","174","23","578","71","9"}
Returns: {"1", "9", "23", "71", "174", "578" }
1)
    
{"172","172","172","23","23"}
Returns: {"23", "23", "172", "172", "172" }
2)
    
{"183","2","357","38","446","46","628","734","741","838"}
Returns: {"2", "38", "46", "183", "357", "446", "628", "734", "741", "838" }

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=7228&pm=4659

Writer:

Andrew_Lazarev

Testers:

PabloGilberto , lbackstrom , brett1479

Problem categories:

Sorting