Statistics

Problem Statement for "Top5"

Problem Statement

We are reviewing applications for a job. Each applicant has taken a test, and we want to restrict our attention to the top 5 applicants according to their scores. Create a class Top5 that contains the method topNames that takes the scores and the names of the applicants as inputs and returns the names of the top 5 applicants (plus ties).

There will be more than 5 names returned if the 6th highest score is tied with the 5th highest score. There will be less than 5 names returned if there are fewer than 5 applicants. The return should list the top applicants in the order in which they applied (the order in which they appear in the inputs). Every two adjacent names in the return should be separated by a comma and space.

Definition

Class:
Top5
Method:
topNames
Parameters:
int[], String[]
Returns:
String
Method signature:
String topNames(int[] score, String[] name)
(be sure your method is public)

Notes

  • the first score correponds to the first name, the second to the second, etc.

Constraints

  • score and name contain the same number of elements
  • the number of elements is between 1 and 50 inclusive
  • each element of score is between 1 and 1000 inclusive
  • each element of name contains only letters
  • each element of name contains between 1 and 20 characters inclusive
  • the elements of name are distinct

Examples

  1. {5,5,7,2,8,3}

    {"a","z","X","A","Tom","Jim"}

    Returns: "a, z, X, Tom, Jim"

    The score of 2 is not in the top 5, so A is eliminated.

  2. {3}

    {"Stickberger"}

    Returns: "Stickberger"

  3. {1,1,8,1,8,1,1}

    {"Y","T","R","E","W","Q","QQ"}

    Returns: "Y, T, R, E, W, Q, QQ"

  4. {8,8,8,8,8,9}

    {"a","b","c","d","e","f"}

    Returns: "a, b, c, d, e, f"

  5. {8,8,8,8,8,7}

    {"a","b","c","d","e","f"}

    Returns: "a, b, c, d, e"

  6. {1000,3,3,3,3,3,3,3,8,9,1,2,3,4,5,3,1}

    {"a","b","c","d","e","f","g","h","i","j","k","n","m","q","r","s","t"}

    Returns: "a, i, j, q, r"

  7. {3,3}

    {"BBBBBBBBBBBBBBBBBBB","AAAAAAAAAAAAAAAAAAAA"}

    Returns: "BBBBBBBBBBBBBBBBBBB, AAAAAAAAAAAAAAAAAAAA"

  8. {1000,1000,1000,1000,1000,1000,999}

    {"a","b","c","d","e","f","g"}

    Returns: "a, b, c, d, e, f"

  9. {6,5,4,3,2}

    {"al","tom","bob","qq","john"}

    Returns: "al, tom, bob, qq, john"

  10. {77,77,77,77}

    {"purple","brown","green","yellow"}

    Returns: "purple, brown, green, yellow"

  11. {99,1,2,3,4,5,6,7,8,9,9,9,9,9,9,9,9,9,9,10,3,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,3,3,3,3,3,3,3,4}

    {"bo","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","y"}

    Returns: "bo, i, j, k, l, m, n, o, p, q, r, s, u, v, w, x, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q"

  12. {123,123,123,123,123,123,123,123}

    {"z","y","xxxxxxxxxxxxxxxxxxxx","w","a","b","c","d"}

    Returns: "z, y, xxxxxxxxxxxxxxxxxxxx, w, a, b, c, d"


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: