TopcoderArchiveVisit Topcoder
SRM7 Aug 2001
SRM 20

LengthSorter

Problem statement, definition, constraints, and public examples.

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)

Constraints

    Examples

      No public sample cases were explicitly marked for this problem in the original data.

      Back to all problems