PROBLEM STATEMENT
We are looking for the perfect String. We have identified all the beautiful
hunks (substrings) that should be in it. We like the order they are in, except
that we would like the shortest hunk that contains an even number of letters to
come first in our perfect String. Create a class HunkGluer that contains the
method perfect that takes the String[] hunks as input and returns the perfect
String.
In case there are no even-length strings in hunks, just glue them together in
order. If there is more than one even-length shortest string, break the tie by
moving the one that appears latest in hunks.
DEFINITION
Class: HunkGluer
Method: perfect
Parameters: String[]
Returns: String
Method Signature (be sure your method is public): String perfect(String[] hunks);
TopCoder will ensure the validity of the inputs. Inputs are valid if all of
the following criteria are met:
- hunks contains between 1 and 50 elements inclusive
- each element of hunks contains between 1 and 20 characters
- each element of hunks contains only uppercase letters A-Z
EXAMPLES
(quotes shown for clarity only)
1) {"A","DE","AE","ABCD"}: return "AEADEABCD"
DE and AE and ABCD are even-length. DE and AE tie for shortest. Since AE
appears later than DE in hunks, it is moved to the front.
2) {"TRY","CELLAR"}: return "CELLARTRY"
3) {"TRY","CELLARS"}: return "TRYCELLARS"
4) {"ABCD","EF","GHIJKL","MNOP"}: return "EFABCDGHIJKLMNOP"