Rank Football Teams
Problem statement
You are given four parallel arrays, wins, draws, scored, and conceded. Index i identifies one football team.
Team i earns 3 * wins[i] + draws[i] points and has goal difference scored[i] - conceded[i].
Rank all teams using these keys, in order:
- More points ranks first.
- If points are equal, larger goal difference ranks first.
- If goal difference is also equal, more goals scored ranks first.
- If all three statistics are equal, the smaller original team index ranks first.
Return a two-element array containing the original indices of the first- and second-ranked teams, in that order.
Function
rankTeams(wins: int[], draws: int[], scored: int[], conceded: int[]) → int[]Examples
Example 1
wins = [3,2,3]draws = [0,4,0]scored = [8,10,7]conceded = [3,4,1]return = [1,2]Team 1 has 10 points, while teams 0 and 2 each have 9. Team 2 has goal difference 6, ahead of team 0 with goal difference 5, so the top two indices are [1,2].
Example 2
wins = [2,2,2,2]draws = [1,1,1,1]scored = [5,6,6,6]conceded = [2,4,3,3]return = [2,3]Every team has 7 points. Teams 0, 2, and 3 have the best goal difference, 3. Teams 2 and 3 then lead on goals scored, and their complete tie is resolved by smaller index, so they rank first and second.
Example 3
wins = [0,1]draws = [4,0]scored = [2,10]conceded = [0,0]return = [0,1]Team 0 has 4 points and team 1 has 3. Points are compared before goal difference or goals scored, so team 0 ranks first.
Constraints
2 ≤ wins.length ≤ 10^5.draws.length = scored.length = conceded.length = wins.length.0 ≤ wins[i], draws[i], scored[i], conceded[i] ≤ 10^9.- Use a wide enough integer type when computing points and goal difference.