Statistics

Problem Statement for "Surname"

Problem Statement

At the carnival this year, there is a contest to determine the best surname. One lucky winner will receive a prize. Each surname is assigned a score which is the sum of the ASCII values of all its characters. You will be given a String[] surnames, where each element contains only uppercase letters ('A'-'Z'). Return the 0-based index of the surname in surnames with the highest score. In case of a tie, return the one with the lowest index.

The ASCII values for uppercase letters are 'A' = 65, 'B' = 66, ..., 'Z' = 90 (which are the integer values of the characters).

Definition

Class:
Surname
Method:
bestSurname
Parameters:
String[]
Returns:
int
Method signature:
int bestSurname(String[] surnames)
(be sure your method is public)

Constraints

  • surnames will contain between 1 and 10 elements, inclusive.
  • Each element of surnames will contain between 1 and 20 characters, inclusive.
  • surnames will contain only uppercase letters ('A'-'Z').

Examples

  1. {"AADSLFKJASDL", "AADSLFJLDJF"}

    Returns: 0

  2. {"AAAAAAA", "ABAAAA"}

    Returns: 0

  3. {"AAAAAAAAAAAAAAAAAA", "ZZZZZZZZZZ"}

    Returns: 0

  4. {"A", "F", "B", "F", "D", "F", "E", "T", "A", "W"}

    Returns: 9

  5. {"AASH", "FZSDGH", "BZADKDT", "FAHTJEA", "DAGADF", "FAHSAD", "EAHAD", "TADHF", "AHADFH", "WAHAFDH"}

    Returns: 2

  6. {"RED", "BLUE", "WHITE", "GREEN"}

    Returns: 2

  7. {"STATEMENT", "EDITOR", "STATEMENT", "PREVIEW", "TEST", "DATA", "SOLUTION", "ALL", "SOLUTIONS", "CORRESPONDENCE"}

    Returns: 9

  8. {"WORK", "OR", "PLAY"}

    Returns: 0

  9. {"AAAAAAAAAAAAAAAAAAAA", "ZZZZZZZZZZZZZZZ"}

    Returns: 1

  10. {"AAAAAAAAAAAAAAAAAAAA", "ZZZZZZZZZZZZZZ"}

    Returns: 0

  11. {"ZZZZZZZZZZZZZZZ", "AAAAAAAAAAAAAAAAAAAA"}

    Returns: 0

  12. {"JONES", "WILLIAMS", "SMITH", "HARPER"}

    Returns: 1

    The values assigned to these strings are as follows: JONES = 74 + 79 + 78 + 69 + 83 = 383 WILLIAMS = 87 + 73 + 76 + 76 + 73 + 65 + 77 + 83 = 610 SMITH = 83 + 77 + 73 + 84 + 72 = 389 HARPER = 72 + 65 + 82 + 80 + 69 + 82 = 450 WILLIAMS is assigned the highest score and its index is returned.

  13. {"JOHNSON", "CHU", "LOPEZ", "SCAFFIDI", "PASQUALE", "KRUMME"}

    Returns: 4

  14. {"PARKER", "PECK", "PICKETT", "POTTER", "PULLMAN"}

    Returns: 4

  15. {"ABA", "BAA", "CAB", "BAC"}

    Returns: 2

    "CAB" and "BAC" have the same ASCII sum. "CAB" is chosen because it has the lower index.

  16. {"BOHR", "FRANKLIN", "TESLA", "NEWTON", "EDISON", "FARNSWORTH", "GUTENBERG", "HOOVER", "MARCONI", "EINSTEIN"}

    Returns: 5

  17. {"BABBAGE", "BOOLE", "BRESENHAM", "TURING", "DIJKSTRA", "BACKUS", "FLOYD", "KERNIGHAN", "BOOCH", "NEUMANN"}

    Returns: 7

  18. {"DEHMELT", "FARADAY", "ALFEROV", "ESSEN", "BIRGE", "CHAMBERLAIN"}

    Returns: 5

  19. {"BBBB", "AAAA", "ZZZ", "AAFF"}

    Returns: 2

  20. {"ZZZZZZ", "KKKKKKZ", "AAAAAAAU"}

    Returns: 0

  21. {"AAAAAAAT", "KKKKKKY", "ZZZZZZ"}

    Returns: 2

  22. {"GABLE", "GRANT", "STEWART", "BOGART", "COOPER"}

    Returns: 2

  23. {"BACALL", "KELLY", "LAKE", "LOCKWOOD", "LANE", "HEPBURN", "NOVAK"}

    Returns: 3

  24. {"GARDNER"}

    Returns: 0

  25. {"AAAAAAAAAA", "BBBBBBBBBBBBBBBBBBBB"}

    Returns: 1

  26. {"ATWILL", "WRAY", "FARRELL", "MCHUGH", "GORDON", "HERBERT", "CURTIZ"}

    Returns: 5

  27. {"A", "AAAAA" }

    Returns: 1

  28. {"AA", "Z" }

    Returns: 0


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: