Statistics

Problem Statement for "MakeTeam"

Problem Statement

A famous football coach picking the 11 players for the starting team in the following way: he chooses the first 11 who come to his office. Then he removes the one with the shortest name. Finally, among all the players now not on the team, he chooses the one with the longest name as "the last player". Ties for removing the shortest are resolved by removing the one who came latest among the tied players. Ties for choosing the longest are resolved by choosing the one who came earliest among the tied players.

We are interested in applying this technique to other sports. Create a class MakeTeam that contains the method lastOne that takes n, the number of players needed to form a team, and the names of players in the order in which they came to the office as inputs and returns the name of the last player. If fewer than n players come to the office, return "NO TEAM".

Definition

Class:
MakeTeam
Method:
lastOne
Parameters:
int, String[]
Returns:
String
Method signature:
String lastOne(int n, String[] names)
(be sure your method is public)

Notes

  • The player removed from the first n may be the last player added (Example 2).

Constraints

  • n is between 1 and 20, inclusive.
  • names contains between 1 and 50 elements, inclusive.
  • Each element of names contains between 1 and 20 characters, inclusive.
  • Each element of names contains only uppercase letters 'A'-'Z'.
  • The elements of names are distinct.

Examples

  1. 4

    {"BO","CHUCK","AL","DON","TOM"}

    Returns: "TOM"

    BO, CHUCK, AL, and DON are the first 4. AL is removed (he came later than BO). That leaves TOM and AL, and TOM has the longer name.

  2. 2

    {"BOB"}

    Returns: "NO TEAM"

    BOB is only one guy. We need 2 to make a team.

  3. 3

    {"JIM","BOB","TOM","AL","HAL"}

    Returns: "TOM"

    JIM, BOB, and TOM are the first 3. TOM is removed, since earlier players are kept in the case of equal length names. Then TOM is added back to the team because his name is longer than AL and he came before HAL.

  4. 3

    {"BILL","JOHN","TOMMY","HAL"}

    Returns: "JOHN"

  5. 1

    {"SEELENFREUND"}

    Returns: "SEELENFREUND"

  6. 3

    {"JACK","TERRY","HAL","JO","AL"}

    Returns: "HAL"

  7. 6

    {"SAM","SAP","SAX","BO","SAD","SSM","SAL","HAL","RED"}

    Returns: "SAL"

  8. 2

    {"STOTTLEMEYER","EMPENTHALLERSTEIN","AL","DEFORESTATION","JON"}

    Returns: "DEFORESTATION"

  9. 20

    {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T"}

    Returns: "T"

  10. 19

    {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T"}

    Returns: "S"

  11. 3

    {"B","BB","BBB","BBBB","BBBBB","BBBBBB","BBBBBBB","BBBBBBBB"}

    Returns: "BBBBBBBB"

  12. 3

    { "AL", "BOB", "TOM" }

    Returns: "AL"

  13. 1

    { "SAD" }

    Returns: "SAD"

  14. 3

    { "A", "BBB", "CCC" }

    Returns: "A"

  15. 1

    { "SAM" }

    Returns: "SAM"

  16. 2

    { "ABCDE", "BCDEF", "ABCD", "DEFG" }

    Returns: "BCDEF"

  17. 3

    { "BOB", "JOE", "CHRIS", "TOM" }

    Returns: "JOE"

  18. 5

    { "AAA", "BBB", "CCC", "DDD", "EEE", "FFF" }

    Returns: "EEE"

  19. 3

    { "BOOOOOO", "B", "A", "S", "Z" }

    Returns: "A"

  20. 3

    { "AL", "ASD", "ADG" }

    Returns: "AL"

  21. 4

    { "JIM", "AL", "HAL", "TOM" }

    Returns: "AL"

  22. 3

    { "AL", "ADG", "AGS" }

    Returns: "AL"

  23. 5

    { "AA" }

    Returns: "NO TEAM"

  24. 5

    { "BOB" }

    Returns: "NO TEAM"

  25. 11

    { "AA", "CC", "CD", "EEW" }

    Returns: "NO TEAM"

  26. 6

    { "SAM", "SAP", "SAX", "BO", "SAD", "SSM", "SAL", "HAL", "RED" }

    Returns: "SAL"

  27. 3

    { "A", "AA", "AAAA" }

    Returns: "A"

  28. 6

    { "AAA", "BBB" }

    Returns: "NO TEAM"

  29. 2

    { "AB", "ABC" }

    Returns: "AB"

  30. 3

    { "JIM", "BOB", "TOM", "AL", "HAL" }

    Returns: "TOM"

  31. 4

    { "JIM", "BOB", "AL", "HAL" }

    Returns: "AL"

  32. 2

    { "AAAAA", "BBB", "FFFFFFFFF", "GGGGGGGGG" }

    Returns: "FFFFFFFFF"

  33. 2

    { "STOTTLEMEYER", "EMPENTHALLERSTEIN", "AL", "DEFORESTATION", "JON" }

    Returns: "DEFORESTATION"

  34. 2

    { "AL", "TIM", "FRED", "JOHN", "FRANK", "TELEPATHY", "YOU", "FORGOT" }

    Returns: "TELEPATHY"

  35. 4

    { "FGH", "HGF", "ASD", "DSA", "QWE", "EWQ", "YUI", "UYT", "OPI", "POI" }

    Returns: "DSA"


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: