Statistics

Problem Statement for "DiamondSeq"

Problem Statement

PROBLEM STATEMENT
Jeweler arranges diamonds to place them on a bracelet. He wants the diamonds
that appear larger to be closer to the middle of the bracelet than the diamonds
that appear smaller. Given the sizes of all diamonds the jeweler needs to
place, determine the sequence in which they need to be arranged on a bracelet,
going from smaller to larger, and then back to smaller ones.

DEFINITION
Class name: DiamondSeq
Method name: arrange
Parameters: String[]
Return type: String[]
Method signature (be sure your method is public): String[] arrange (String[]
diamonds);

diamonds specifies the size and the color of each diamond. The string is
formatted as follows (here and below, quotation marks and angular brackets '<'
and '>' are for clarity only)
"<SIZE><COLOR CODE>"
Diamond size is expressed in whole carat points (one carat point is 1/100 of a
carat). Diamond color is expressed as a single-character code from 'D'
(colorless) to 'Z' (strong yellow color), inclusive. For example, "95F"
specifies a diamond weighing 95 carat points (0.95 carats) and the color code
'F'.

The jeweler believes that less colored diamonds (with color codes appearing
earlier in the alphabet) look slightly larger. For example, he believes that a
"95D" diamond looks larger than "95F". When the jeweler compares two diamonds
of different color, he adds one carat point for each step in the color code
difference to a less colored diamond. For example, jeweler considers a "10D"
diamond larger than a "12G" diamond, because there is a 3-step difference
between 'D' and 'G', making (10+3) > 12.

Your method should return an arrangement of diamonds going from smaller to
larger, and then back to smaller ones. The smallest diamond (according to
jeweler's criteria set forth above) has to be the first element of the result;
the second smallest diamond has to be the last element of the result; the third
smallest diamond has to be the second element of the result, and so on. This
way, the largest diamond will end up in the middle of the result.

TopCoder will ensure the validity of the inputs. Inputs are valid if all of the
following criteria are met:
- diamonds has 1 to 50 elements, inclusive.
- Each element of the diamonds is formatted as "<SIZE><COLOR>".
- <SIZE> is between 5 and 500, inclusive, with no leading '0' (zero) characters.
- <COLOR> is an upper-case letter from 'D' to 'Z', inclusive.

NOTE
When two diamonds appear the same according to the jeweler's criterion (for
example, "10D" and "11E"), consider the diamond appearing earlier in the input
sequence to be smaller. See example 3.

EXAMPLES
1. If diamonds={"10D", "11D", "12D", "13D", "14D"}, your method should return
{"10D", "12D", "14D", "13D", "11D"}.
2. If diamonds={"10H", "10G", "10F", "10E", "10D"}, your method should return
{"10H", "10F", "10D", "10E", "10G"}.
3. If diamonds={"10G", "11H", "10F"}, your method should return {"10G", "10F",
"11H"}. Note that {"11H", "10F", "10G"} would be an incorrect result: although
"10G" and "11H" compare as equal, "10G" appears earlier in the input sequence,
and therefore should be considered smaller.
4. If diamonds={"256J", "128I", "64H", "32G", "16F", "8E"}, your method should
return {"8E", "32G", "128I", "256J", "64H", "16F"}.

Definition

Class:
DiamondSeq
Method:
arrange
Parameters:
String[]
Returns:
String[]
Method signature:
String[] arrange(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: