FastPrepRank Football Teams

Rank Football Teams

TikTok logoTikTok● EasyINTERNOA
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 teams by more points first, then by larger goal difference. If both values are equal, rank the smaller original index first. Return the original indices of the first- and second-ranked teams.

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. Teams 0 and 2 have 9 points, and team 2 wins their tie with goal difference 6.

Example 2

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, so points decide the order before goal difference.

Constraints

  • 2 <= wins.length <= 100000
  • draws.length = scored.length = conceded.length = wins.length
  • 0 <= wins[i], draws[i], scored[i], conceded[i] <= 1000000000
  • Use a 64-bit integer for ranking keys.

More TikTok problems

See TikTok 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…