When comparing two names, the one with the larger weight is considered better. In case of a tie, the one that comes earlier lexicographically is better. But there is one exception - the name JOHN is the best name of all.
You are given a String[] names, each element of which
contains a single name. Sort the names from best to worst and return the
sorted String[].
names will contain between 1 and 50 characters, inclusive.
names will contain only uppercase letters ('A'-'Z').
{"JOHN", "PETR", "ACRUSH"}
Returns: {"JOHN", "ACRUSH", "PETR" }
PETR has weight 59, ACRUSH has weight 70 and JOHN has a weight of only
47. But nevertheless JOHN is the best name, ACRUSH takes second place
and PETR is the last.
{"GLUK", "MARGARITKA"}
Returns: {"MARGARITKA", "GLUK" }
MARGARITKA is definitely better than GLUK.
{"JOHN", "A", "AA", "AAA", "JOHN", "B", "BB", "BBB", "JOHN", "C", "CC", "CCC", "JOHN"}
Returns:
{"JOHN",
"JOHN",
"JOHN",
"JOHN",
"CCC",
"BBB",
"CC",
"BB",
"AAA",
"C",
"AA",
"B",
"A" }
AA and B both have the same weight, but AA is better as it comes earlier
lexicographically. For the same reason, AAA is better than C and BBB is
better than CC.
{"BATMAN", "SUPERMAN", "SPIDERMAN", "TERMINATOR"}
Returns: {"TERMINATOR", "SUPERMAN", "SPIDERMAN", "BATMAN" }
Here are some superheroes sorted by their names.