Players With Zero or One Losses
Medium
LC #2225
hash mapcountingsortingNot attempted yet
Each item of matches is [winner, loser] for one
game. Return a list of two lists:
- players who played and never lost, and
- players who lost exactly once,
each sorted in increasing order. Only count players who appear in at least one match.
Example 1
Input: matches = [[3, 1], [2, 1], [3, 4], [5, 2]]
Output: [[3, 5], [2, 4]]
1 lost twice; 2 and 4 lost once; 3 and 5 never lost.
Example 2
Input: matches = [[1, 2]]
Output: [[1], [2]]
Example 3
Input: matches = [[4, 7], [7, 4], [4, 7]]
Output: [[], [4]]
Constraints
- 1 ≤ matches.length ≤ 10⁵
- 1 ≤ player ids ≤ 10⁶
- A player never plays themselves.