Find the Number of Winning Players

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.
I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.
You are given an integer n representing the number of players in a game and a 2D array pick where pick[i] = [x<sub>i</sub>, y<sub>i</sub>] represents that the player x<sub>i</sub> picked a ball of color y<sub>i</sub>.
Player i wins the game if they pick strictly more than i balls of the same color. In other words,
Player 0 wins if they pick any ball.
Player 1 wins if they pick at least two balls of the same color.
...
Player
iwins if they pick at leasti + 1balls of the same color.
Return the number of players who win the game.
Note that multiple players can win the game.
LeetCode Problem - 3238
class Solution {
public int winningPlayerCount(int n, int[][] pick) {
// Initialize the answer to keep track of the number of winning players
int answer = 0;
// Create a 2D array to count the number of times each player picks each color
int[][] colorCounts = new int[n][11]; // Assuming there are 10 colors (index 1 to 10)
// Iterate through each pick and increment the corresponding player's color count
for(int[] p : pick) {
int player = p[0]; // Player index
int color = p[1]; // Color index
colorCounts[player][color]++;
}
// Iterate through each player's color count to determine if they are a winning player
for(int i = 0; i < n; i++) {
for(int val : colorCounts[i]) {
// A player is considered a winner if they have picked a color more times than their index
if(val > i) {
answer++; // Increment the count of winning players
break; // Stop checking further colors for this player
}
}
}
// Return the total number of winning players
return answer;
}
}




