Return the Top Two Teams by Points, Goal Difference, and Tie Breakers
Company: Capital One
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Online Assessment
Return the indices of the first-place and second-place teams from four arrays of competition statistics.
Team `i` has `wins[i]` wins, `draws[i]` draws, `scored[i]` goals scored, and `conceded[i]` goals conceded. Its points are `3 * wins[i] + draws[i]`, and its goal difference is `scored[i] - conceded[i]`.
### Function Signature
`rank_top_two(wins: list[int], draws: list[int], scored: list[int], conceded: list[int]) -> list[int]`
### Ranking Rules
Compare teams using these criteria, in order, with the larger value ranked first:
1. Points.
2. Goal difference.
3. Goals scored.
4. Team index.
The goals-scored and larger-index tie rules are explicit conventions for this exercise, matching descending comparison of `(points, goal_difference, goals_scored, index)`.
### Output
Return `[first_place_index, second_place_index]`. Team indices are zero-based, and the two returned indices must be distinct.
### Constraints
- All four arrays have the same length `n`, with `2 <= n <= 100000`.
- Every array element is an integer in `[0, 1000000]`.
- Ranking uses the supplied statistics; no additional consistency checks on the competition are required.
### Examples
Input: `wins = [2,1,2], draws = [0,3,0], scored = [5,8,7], conceded = [2,5,3]`
Output: `[2,1]`
All teams have 6 points. Team 2 has goal difference 4. Teams 0 and 1 have goal difference 3, so team 1 ranks next because it scored more goals.
Input: `wins = [0,0,0], draws = [0,0,0], scored = [0,0,0], conceded = [0,0,0]`
Output: `[2,1]`
Overview: Rank competition teams by points, goal difference, goals scored, and an explicit index tie rule, then return the first two team indices.
You are given four integer arrays of the same length `n` describing the teams of a competition. Team `i` (zero-based) has `wins[i]` wins, `draws[i]` draws, `scored[i]` goals scored and `conceded[i]` goals conceded.
Team `i`'s points are `3 * wins[i] + draws[i]`, and its goal difference is `scored[i] - conceded[i]`.
Compare teams using these criteria, in order, with the larger value ranked first:
1. Points.
2. Goal difference.
3. Goals scored.
4. Team index.
The goals-scored and larger-index tie rules are explicit conventions for this exercise: the ranking is exactly the descending comparison of the tuple `(points, goal_difference, goals_scored, index)`. Because team indices are distinct, no two teams ever compare equal, so the ranking is a strict total order and the answer is unique.
Return `[first_place_index, second_place_index]`, the indices of the first-place and second-place teams in that order. Team indices are zero-based and the two returned indices are always distinct.
All intermediate values fit in a signed 32-bit integer: points are at most `3 * 1000000 + 1000000 = 4000000` and goal difference lies in `[-1000000, 1000000]`. No value can exceed 2^31 - 1, so Java `int` and C++ `int` are sufficient (no `long` / `long long` is needed).
Example 1:
Input: `wins = [2, 1, 2]`, `draws = [0, 3, 0]`, `scored = [5, 8, 7]`, `conceded = [2, 5, 3]`
Output: `[2, 1]`
Explanation: all teams have 6 points. Team 2 has goal difference 4, while teams 0 and 1 have goal difference 3, so team 2 is first. Between teams 0 and 1 the goal differences tie, so goals scored decides and team 1 (8 goals vs 5) is second.
Example 2:
Input: `wins = [0, 0, 0]`, `draws = [0, 0, 0]`, `scored = [0, 0, 0]`, `conceded = [0, 0, 0]`
Output: `[2, 1]`
Explanation: every team ties on points, goal difference and goals scored, so the larger index ranks first: team 2 is first and team 1 is second.
Constraints
- All four arrays have the same length n, with 2 <= n <= 100000.
- Every array element is an integer in [0, 1000000]: 0 <= wins[i], draws[i], scored[i], conceded[i] <= 1000000.
- Ranking uses only the supplied statistics; no additional consistency checks on the competition are required.
- Derived from the bounds above: points = 3 * wins[i] + draws[i] is at most 4000000 and goal difference = scored[i] - conceded[i] lies in [-1000000, 1000000], so every intermediate value fits in a signed 32-bit integer.
- The returned list always contains exactly two distinct zero-based indices, in the order [first_place_index, second_place_index].
Examples
Input: ([2, 1, 2], [0, 3, 0], [5, 8, 7], [2, 5, 3])
Expected Output: [2, 1]
Explanation: Source example 1: all three teams have 6 points; team 2's goal difference +4 beats +3, and between teams 0 and 1 (both +3) team 1 scored 8 > 5.
Input: ([0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0])
Expected Output: [2, 1]
Explanation: Source example 2: complete tie on points, goal difference and goals scored, so the larger indices rank first.
Hints
- Every comparison between two teams is decided by the same fixed sequence of four quantities; computing those quantities once per team makes each comparison uniform.
- The last criterion is the team index, which differs for every team, so no two teams can ever compare equal and the answer is never ambiguous.
- The question asks only for the first two places, not for the position of every team.