Ctrl K

Color Streak Winners

Easy
A game has players people numbered from zero. Each of them draws colored chips from a bag; an entry draws[i] = [p, c] means player p drew a chip of color c. The higher a player's number, the tougher their winning condition: player p wins if at least p + 1 of their chips share one color. So player 0 only has to draw any chip at all, while player 2 needs three chips of the same color. Return how many players won (there may be several winners, or none).
Example 1
players=3, draws=[[2, 5], [0, 7], [2, 5], [1, 3], [2, 5]] → 2

Player 0 drew something, so they win. Player 1 needs two chips of one color but has just one. Player 2 needs three of one color and has exactly three of color 5. Two winners.

Example 2
players=4, draws=[[3, 1], [3, 2], [3, 3], [3, 4]] → 0

Player 3 drew four chips, all of different colors, and nobody else drew anything.

Example 3
players=2, draws=[[1, 0], [1, 0]] → 1
Constraints
  • 2 ≤ players ≤ 10
  • 1 ≤ len(draws) ≤ 100
  • draws[i] = [p, c], 0 ≤ p < players, 0 ≤ c ≤ 10
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Candidate With Most Votes EasyValues One Apart EasyEven Piles of Cards EasyMatching Domino Tiles EasyWords From Letter Tiles Easy
loading Python…
Input
players=3, draws=[[2, 5], [0, 7], [2, 5], [1, 3], [2, 5]]
Expected
2

Run checks the first 3 tests in your browser. Submit checks all 72 tests on the server, hidden ones included.