FastPrepRank Football Teams

Rank Football Teams

Persona logoPersona● EasyINTERNNEW GRADOA
Learn

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:

  1. More points ranks first.
  2. If points are equal, larger goal difference ranks first.
  3. If both values 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,3,3,3]return = [0,1]

Every team has 7 points and goal difference 3. The complete tie is resolved by smaller original index, so teams 0 and 1 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, so team 0 ranks first even though team 1 has the larger goal difference.

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.

More Persona problems

See Persona hiring insights
public int[] rankTeams(int[] wins, int[] draws, int[] scored, int[] conceded) {
    // write your code here
}
wins[3,2,3]
draws[0,4,0]
scored[8,10,7]
conceded[3,4,1]
expected[1,2]
Checking account…