TopCoder problem "NamesList" used in TCHS SRM 35 (Division I Level One)



Problem Statement

    

You are working on setting up a new filing system, and need to know which k-th letter occurs most frequently among the names of your clients. Given String[] names, each element of which contains the name of a client, and int k, the 1-based index of the character to examine, return a String indicating the k-th letter that appears most often. Ignore any names containing less than k characters. If multiple k-th letters appear the same number of times, return the one among them that comes first alphabetically.

 

Definition

    
Class:NamesList
Method:popularInitial
Parameters:String[], int
Returns:String
Method signature:String popularInitial(String[] names, int k)
(be sure your method is public)
    
 

Constraints

-names will contain between 1 and 50 elements, inclusive.
-Each element of names will contain between 1 and 50 uppercase letters ('A'-'Z'), inclusive.
-k will be between 1 and 50, inclusive.
-At least one element of names will contain at least k characters.
 

Examples

0)
    
{"ANNE", "BILL", "BOB"}
1
Returns: "B"
Here, we just want the first character. There is 1 'A' and 2 'B's.
1)
    
{"ANNE", "BILL", "WILL"}
2
Returns: "I"
Looking at the second character, we have 'N', 'I', 'I'.
2)
    
{"ANN", "BOB", "JAMES"}
5
Returns: "S"
Only one name has five characters, and the fifth character is an 'S'.
3)
    
{"STEVE"}
2
Returns: "T"
With only one name, this is pretty trivial.
4)
    
{"JILL", "WILL", "CAL"}
3
Returns: "L"
All the same third letter.
5)
    
{"ANN", "ALEX", "BOB", "BILL"}
1
Returns: "A"
Two 'A' and two 'B', so we break the tie by taking the earlier letter.

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=8037

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10771&pm=8037

Writer:

timmac

Testers:

PabloGilberto , brett1479 , Olexiy , ivan_metelsky

Problem categories:

Brute Force, Simple Search, Iteration