Find Players With Zero or One Losses - Problem
You are given an integer array matches where matches[i] = [winneri, loseri] indicates that the player winneri defeated player loseri in a match.
Return a list answer of size 2 where:
answer[0]is a list of all players that have not lost any matches.answer[1]is a list of all players that have lost exactly one match.
The values in the two lists should be returned in increasing order.
Note:
- You should only consider the players that have played at least one match.
- The testcases will be generated such that no two matches will have the same outcome.
Input & Output
Example 1 — Basic Tournament
$
Input:
matches = [[1,3],[2,3],[3,6],[5,6],[5,7],[4,5],[4,8],[4,9],[10,4],[10,9]]
›
Output:
[[1,2,10],[4,5,6,7,8]]
💡 Note:
Players 1, 2, 10 never lost (0 losses). Players 4, 5, 6, 7, 8 lost exactly once. Player 3 lost twice (excluded), player 9 lost twice (excluded).
Example 2 — Simple Case
$
Input:
matches = [[2,3],[1,3],[3,4]]
›
Output:
[[1,2],[4]]
💡 Note:
Players 1 and 2 never lost. Player 4 lost exactly once. Player 3 lost twice (excluded from both lists).
Example 3 — Single Match
$
Input:
matches = [[1,2]]
›
Output:
[[1],[2]]
💡 Note:
Player 1 won and never lost (0 losses). Player 2 lost exactly once.
Constraints
- 1 ≤ matches.length ≤ 105
- matches[i].length == 2
- 1 ≤ winneri, loseri ≤ 105
- winneri ≠ loseri
- All matches[i] are unique
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code