Skip to main content
Back to problems
#3238
Easy Algorithms

Find the number of winning players

Array Hash Table Counting
60.4% acceptance
Feb 25, 2026
99
27
You are given an integer n representing the number of players in a game and a 2D array pick where pick[i] = [xi, yi] represents that the player xi picked a ball of color yi. Player i wins the game if they pick strictly more than i balls of the same color. Player 0 wins if they pick any ball. Player 1 wins if they pick at least two balls of the same color. Player i wins if they pick at least i + 1 balls of the same color. Return the number of players who win the game.

Solution

Rust
Time O(n)
Space O(n)
LeetCode
solution.rs
impl Solution {
  pub fn winning_player_count(n: i32, pick: Vec<Vec<i32>>) -> i32 {
    let n = n as usize;
    // count[player][color] = # balls of that color picked by that player
    let mut count = vec![[0i32; 11]; n];
    for p in &pick {
      count[p[0] as usize][p[1] as usize] += 1;
    }
    let mut winners = 0i32;
    for i in 0..n {
      let max_color = *count[i].iter().max().unwrap();
      if max_color >= (i as i32 + 1) {
        winners += 1;
      }
    }
    winners
  }
}