TopCoder problem "ScheduleStrength" used in SRM 265 (Division I Level One , Division II Level Two)

Problem Statement

    A common way to rank athletic teams is based on each team's winning percentage. However, when two teams have similar percentages, the team that played against better opponents will be ranked above the team that had easier opponents. The measure of how difficult a team's opponents are, is known as the team's strength of schedule. A team that has faced tough opponents is said to have a strong schedule, and a team with poor opponents is said to have a weak schedule.

We will use the cumulative winning percentage of Team X's opponents (the teams that Team X played against) as a measure of Team X's strength of schedule. This percentage is the number of wins recorded by Team X's opponents divided by the total games they played, excluding games that were played against Team X.

Given a String[] of teams that contains the name of each team and a String[] results that indicates the outcome of games played during the season, return a String[] containing the names of the teams, ordered from strongest schedule to weakest. Teams with equivalent schedule strengths should appear in increasing alphabetical order.

Element i of results corresponds to team i whose name is found in teams at index i. Character j of element i of results will be one of 'W', 'L' or '-' respectively indicating whether team i won, lost, or did not play a game against team j.



Parameters:String[], String[]
Method signature:String[] calculate(String[] teams, String[] results)
(be sure your method is public)


-teams will contain between 3 and 50 elements, inclusive.
-teams and results will contain the same number of elements.
-Each element of teams will contain between 1 and 50 characters, inclusive.
-Each element of teams will only contain uppercase letters ('A'-'Z').
-Each element of teams will be distinct.
-Each element of results will contain N characters, where N is the number of elements in teams.
-Each element of results will only contain 'W', 'L' and '-'.
-The ith character of the ith element of results will be '-'.
-If the jth character of the ith element of results is 'W' then the ith character of the jth element of results will be 'L', and vice versa.
-Every team will play at least two games.


This season's results gives us the following win/loss records:
        wins - losses
BEARS      3 - 1
GIANTS     2 - 2  (1 loss to the BEARS)
COWBOYS    2 - 1  (1 win against the BEARS)
BRONCOS    1 - 2  (1 loss to the BEARS)
DOLPHINS   1 - 1  (1 loss to the BEARS)
LIONS      0 - 2  (did not play the BEARS)

The BEARS's opponents are the GIANTS, COWBOYS, BRONCOS and DOLPHINS. Their combined win/loss record is 6-6 (6 wins, 6 losses), but when we exclude games played against the BEARS, this record becomes 5-3. So, the BEARS have a schedule strength of 5/8 = .625

Here are the cumulative records and winning percentages calculated for each team:
           Record    Winning %
BEARS      5 - 3    5/8 = .625
GIANTS     4 - 4    4/8 = .5
COWBOYS    4 - 3    4/7 = .5714
BRONCOS    4 - 3    4/7 = .5714
DOLPHINS   3 - 2    3/5 = .6
LIONS      2 - 3    2/5 = .4
{"E", "D", "C", "B", "Z"}
Returns: {"D", "E", "C", "Z", "B" }

Problem url:

Problem stats url:




PabloGilberto , brett1479 , Olexiy

Problem categories:

Math, Sorting, String Parsing