Players With Zero or One Losses

Big-O & the Python Toolkit, problem 6 of 7

Players With Zero or One Losses

Medium

LC #2225

hash mapcountingsorting

Not 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.

Python

Loading draft…

Test results

8 tests available

No results yet

Run tests your code against the examples; Submit runs the hidden tests too.

3 examples, 5 hidden

Run examples, then submit all tests.