Statistics

Problem Statement for "OldestOne"

Problem Statement

Our student data is a mess! Each student is described with one String. At least a student's data always starts with her name, then her age, and then her address, and none of these is ever missing. The name and age are separated by one or more spaces and the age is separated from the address by one or more spaces. There may be leading and trailing spaces in a student's data.

A student's name always consists only of uppercase letters 'A'-'Z' and embedded (not leading or trailing) spaces. A student's age always consists of exactly 1, 2, or 3 digits, and its leading digit is not a zero. A student's address always contains at least one non-space character.

We need to find the name of the oldest student. If there are several, we want the one that appears earliest in the data. The name should include its embedded spaces (even if there are several consecutive embedded spaces), but no leading spaces and no trailing spaces.

Create a class OldestOne that contains a method oldest that is given a String[] data where each element is the data for a student, and that returns the name of the oldest student.

Definition

Class:
OldestOne
Method:
oldest
Parameters:
String[]
Returns:
String
Method signature:
String oldest(String[] data)
(be sure your method is public)

Constraints

  • data will contain between 1 and 50 elements inclusive
  • Each element of data will contain between 5 and 50 characters inclusive
  • Each character in each element of data will be an uppercase letter 'A'-'Z', a digit '0'-'9' or a space (' ').
  • Each element of data will contain a name followed by an age and address, formatted as explained above, and may contain leading and trailing spaces.
  • The name in each element will contain only uppercase letters 'A'-'Z' and embedded spaces.
  • The age in each element will have no leading zeroes and will consist of between 1 and 3 digits inclusive.

Examples

  1. {"DOUG JONES 22 213 ALDEN LANE"," BOB A SMITH 102 CLARK ST"}

    Returns: "BOB A SMITH"

    Bob is clearly the oldest of these students. Note that the leading spaces and trailing spaces in the name are not included in the return, but the spaces embedded in the name must be preserved.

  2. {"DOUG JONES 102 213 ALDEN LANE"," BOB A SMITH 102 CLARK ST", "A 1 999ELM"}

    Returns: "DOUG JONES"

    Now Doug Jones is 102 and is tied for oldest. A has an age of 1 (the 999 is part of his address). Bob is also 102, but comes later in the data than Doug.

  3. {"DOUG JONES 122 213 ALDEN LANE"," BOB A SMITH 102 CLARK ST", "A 199 ELM"}

    Returns: "A"

    A has a one letter name, but is the oldest.

  4. {"DOUG JONES 122 213 ALDEN LANE"," BOB A SMITH 102 CLARK ST", "AL JOHNSON CARVER 199 ELM"}

    Returns: "AL JOHNSON CARVER"

  5. {" DOUG JONES 122 213 ALDEN LANE", " BOB A SMITH 102 3", " J O H N N Y 199 ELM"}

    Returns: "J O H N N Y"

    I don't know why Johnny likes to put spaces in his name, but we have to respect his wishes.

  6. {"A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","AB 15 9","A 10 9","A 10 9","A 10 9","A 10 9","A 9 9","A 10 9","A 11 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9","A 10 9"}

    Returns: "AB"

  7. {" AL ALAL AL AL AL AL AL AL AL AL AL AL 921 AA"}

    Returns: "AL ALAL AL AL AL AL AL AL AL AL AL AL"

  8. {" AL ALAL AL AL AL AL AL AL AL AL AL AL 921 AA","B 99 9"}

    Returns: "AL ALAL AL AL AL AL AL AL AL AL AL AL"

  9. {" AL ALAL AL AL AL AL AL AL AL AL AL AL 921 AA","B 990 9"}

    Returns: "B"

  10. {"A 10 9","B 9 9","C C 8 9","D 7 9","E 6 9","F 5 9","GG 4 9","H H H 3 9"}

    Returns: "A"

  11. {"A 10 9","B 90 9","C C 80 9","D 709 9","E 699 9","F 5 9","GG 54 9","H H H 30 9"}

    Returns: "D"

  12. {"A A 10 9","B 90 9","C C 80 9"," D D A 709 9", "E 699 9","F 5 9","GG 54 9","H H H 30 9"}

    Returns: "D D A"

  13. {"A A 10 9","B 90 9","C C 80 9"," D D A 709 9", "E 699 9","F 5 9","GG 54 9","H H H 730 9"}

    Returns: "H H H"

  14. {"A 1 A 7 A 1","A 2 A 7 A 1","A 3 A 7 A 1","A A 4 A 7 A 1"}

    Returns: "A A"

  15. {"A 1 A 7 A 1","B 2 A 7 A 1","C 3 A 7 A 1","A A 3 A 7 A 1"}

    Returns: "C"

  16. {"A 1 A 7 A 1","ABCDEEEEEEEEEEEEEEEEEEEEEEEEEEEE E 20 A 7 A 1","A 3 A 7 A 1","A A 4 A 7 A 1"}

    Returns: "ABCDEEEEEEEEEEEEEEEEEEEEEEEEEEEE E"

  17. { " EAM MEA 123 321 RD FFF FGF F", " EAS SDSSD 124 123 43 DESES", "EEEE EEEE 123 232 ESDEDS", " EEEEE WWWWW 125 128REREEER" }

    Returns: "EEEEE WWWWW"

  18. { "DOUG JONES 22 213 ALDEN LANE", " BOB A SMITH 102 CLARK ST" }

    Returns: "BOB A SMITH"

  19. { " HELLO THERE 29 AKAK", " NO W H II TE 33 AAA444" }

    Returns: "NO W H II TE"

  20. { "A A A 111 111" }

    Returns: "A A A"

  21. { "DOUG JONES 999 213 ALDEN LANE", " BOB A SMITH 999 CLARK ST" }

    Returns: "DOUG JONES"


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: