TopCoder problem "LargestCountry" used in TCHS07 Beta 2 (Division I Level One)



Problem Statement

    

Given a world map, you must determine the country that has the largest territory. The map is given as a String[] worldMap, where each character represents a square with an area of 1. Unoccupied squares are represented by space characters (' '). Occupied squares are represented by uppercase letters ('A'-'Z') that denote the occupying country. The area of a country's territory is the total area of its occupied squares. Return a String containing exactly one character - the name of the largest country. In case of a tie, return the largest country whose name comes first alphabetically.

 

Definition

    
Class:LargestCountry
Method:getLargest
Parameters:String[]
Returns:String
Method signature:String getLargest(String[] worldMap)
(be sure your method is public)
    
 

Constraints

-worldMap will contain between 1 and 50 elements, inclusive.
-Each element of worldMap will contain between 1 and 50 characters, inclusive.
-All elements of worldMap will contain the same number of characters.
-Each element of worldMap will contain only uppercase letters ('A'-'Z') and spaces (' ').
-At least one element of worldMap will contain a non-space character.
 

Examples

0)
    
{"AAA","CA "}
Returns: "A"
Country "A" has the largest territory.
1)
    
{"ACA","CAC"}
Returns: "A"
Countries "A" and "C" both occupy 3 squares. "A" is returned because it comes earlier alphabetically.
2)
    
{"ABZ","CXC"}
Returns: "C"
"C" is the largest country.
3)
    
{"AAA","CA "}
Returns: "A"
4)
    
{" A "," B "," X "," B "," X "," X "}
Returns: "X"

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10715&pm=7535

Writer:

gevak

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Simple Search, Iteration