Top Two Teams by Points, Then Goal Difference, Then Goals Scored
Company: Capital One
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: HR Screen
A league records four statistics for each of its `n` teams in four parallel arrays: `wins[i]`, `draws[i]`, `scored[i]` (goals scored) and `conceded[i]` (goals conceded) all describe team `i`. Rank the teams and return the indices of the first-placed and second-placed teams.
A team earns 3 points for each win and 1 point for each draw, so team `i` has `points = 3 * wins[i] + draws[i]`.
### Function Signature
```python
def top_two_teams(wins: list[int], draws: list[int], scored: list[int], conceded: list[int]) -> list[int]:
```
### Rules
Teams are ranked by the following keys, each one used only to break a tie in all of the previous keys:
1. More points ranks higher.
2. Greater goal difference, `scored[i] - conceded[i]`, ranks higher.
3. More goals scored, `scored[i]`, ranks higher.
4. The smaller index ranks higher.
Return a list of exactly two indices, `[first, second]`. Because the last key never ties, the answer is unique.
### Constraints
- `2 <= n <= 100000`, where `n` is the common length of all four arrays
- `0 <= wins[i] <= 1000` and `0 <= draws[i] <= 1000`
- `0 <= scored[i] <= 100000` and `0 <= conceded[i] <= 100000`
- Goal difference can be negative.
### Examples
**Example 1**
- Input: `wins = [1, 3, 2, 3]`, `draws = [2, 0, 3, 0]`, `scored = [5, 7, 6, 9]`, `conceded = [5, 3, 5, 5]`
- Output: `[3, 1]`
- Explanation: Points are `[5, 9, 9, 9]`. Teams `1`, `2` and `3` tie on 9 points. Their goal differences are `4`, `1` and `4`, so team `2` drops behind. Teams `1` and `3` still tie, and team `3` scored more goals (9 against 7), so team `3` is first and team `1` is second.
**Example 2**
- Input: `wins = [2, 2]`, `draws = [1, 1]`, `scored = [4, 4]`, `conceded = [2, 2]`
- Output: `[0, 1]`
- Explanation: The two teams tie on every statistic, so the smaller index ranks higher.
**Example 3**
- Input: `wins = [0, 4, 3]`, `draws = [5, 0, 4]`, `scored = [2, 10, 3]`, `conceded = [1, 2, 3]`
- Output: `[2, 1]`
- Explanation: Points are `[5, 12, 13]`. Team `2` is first on points even though team `1` has the far better goal difference (8 against 0); goal difference only matters when points are equal.
Overview: Given parallel arrays of wins, draws, goals scored and goals conceded for each team, compute points as three per win plus one per draw and return the indices of the top two teams. Ties are broken by goal difference, then goals scored, then index, testing multi-key comparison and careful tie handling.
Read the full Capital One Software Engineer interview experience this question came from