Sports League Table Ranking
Description:
Note: There is a harder version (Sports League Table Ranking (with Head-to-head)) of this.
Description
You organize a sports league in a round-robin-system. Each team meets all other teams. In your league a win gives a team 2 points
, a draw gives both teams 1 point
. After some games you have to compute the order of the teams in your league. You use the following criteria to arrange the teams:
- Points
- Scoring differential (the difference between goals scored and those conceded)
- Goals scored
First you sort the teams by their points. If two or more teams reached the same number of points, the second criteria comes into play and so on. Finally, if all criteria are the same, the teams share a place.
Input
number
: Number of teams in your league.games
: An array of arrays. Each item represents a played game with an array of four elements[TeamA,TeamB,GoalA,GoalB]
(TeamA
played againstTeamB
and scoredGoalA
goals and concededGoalB
goals ).
Output
positions
: An array of positions. Thei
-th item should be the position of thei
-th team in your league.
Example
number = 6
games = [[0, 5, 2, 2], // Team 0 - Team 5 => 2:2
[1, 4, 0, 2], // Team 1 - Team 4 => 0:2
[2, 3, 1, 2], // Team 2 - Team 3 => 1:2
[1, 5, 2, 2], // Team 1 - Team 5 => 2:2
[2, 0, 1, 1], // Team 2 - Team 0 => 1:1
[3, 4, 1, 1], // Team 3 - Team 4 => 1:1
[2, 5, 0, 2], // Team 2 - Team 5 => 0:2
[3, 1, 1, 1], // Team 3 - Team 1 => 1:1
[4, 0, 2, 0]] // Team 4 - Team 0 => 2:0
You may compute the following table:
Rank | Team | For : Against | GD | Points |
---|---|---|---|---|
1. | Team 4 | 5 : 1 | +4 | 5 |
2. | Team 5 | 6 : 4 | +2 | 4 |
3. | Team 3 | 4 : 3 | +1 | 4 |
4. | Team 0 | 3 : 5 | -2 | 2 |
4. | Team 1 | 3 : 5 | -2 | 2 |
6. | Team 2 | 2 : 5 | -3 | 1 |
Team 5 and Team 3 reached the same number of points. But since Team 5 got a better scoring differential, it ranks better than Team 3. All values of Team 0 and Team 1 are the same, so these teams share the fourth place.
In this example you have to return the array [4, 4, 6, 3, 1, 2]
.
Similar Kata:
Stats:
Created | Dec 31, 2019 |
Published | Dec 31, 2019 |
Warriors Trained | 2131 |
Total Skips | 44 |
Total Code Submissions | 5154 |
Total Times Completed | 584 |
Java Completions | 109 |
JavaScript Completions | 256 |
Ruby Completions | 37 |
Python Completions | 198 |
C# Completions | 19 |
Total Stars | 76 |
% of votes with a positive feedback rating | 90% of 123 |
Total "Very Satisfied" Votes | 104 |
Total "Somewhat Satisfied" Votes | 13 |
Total "Not Satisfied" Votes | 6 |
Total Rank Assessments | 5 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 8 kyu |