Statistics

Problem Statement for "LengthSorter"

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


      This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
      This problem was used for: