TopCoder problem "LengthSorter" used in SRM 20 (Division I Level One , Division II Level One)



Problem Statement

    
Class name: LengthSorter
Method name: sortByLength
Parameters: String[]
Returns: String[]


Implement a class LengthSorter, which contains a method sortByLength.  The
method sorts a String[] of elements by the length of the elements, longest to
shortest.  If multiple Strings have the same length, their relative order in
the output should be the same as their relative order in the input.  


Here is the method signature:
String[] sortByLength(String[] stringList)
Be sure your method is public.


INPUT:
A String[] containing between 1 and 50 elements, inclusive. Each element of the
String[] will be between 1 and 50 characters in length, inclusive.
Strings contain only letters, spaces, and numbers.
TopCoder will ensure the input is valid.


OUTPUT:
A String[] containing the same Strings as the input, sorted longest to shortest.


EXAMPLES:

Input: {"Top", "Coder", "comp", "Wedn", "at", "midnight"}
Output:{"midnight", "Coder", "comp", "Wedn", "Top", "at"}

Input: {"one", "three", "five"}
Output:{"three", "five", "one"}


Input: {"I","love","Cpp"}
Output:{"love","Cpp","I"}
 

Definition

    
Class:LengthSorter
Method:sortByLength
Parameters:String[]
Returns:String[]
Method signature:String[] sortByLength(String[] param0)
(be sure your method is public)
    

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=3019&pm=131

Writer:

Soli

Testers:

Problem categories: