Easy HashMap Solution
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem involves determining how many players win the game based on the number of b
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem involves determining how many players win the game based on the number of balls they pick of the same color. Each player has a specific condition to win: they need to pick a certain number of balls of the same color. For example, Player 0 wins if they pick at least 1 ball, Player 1 wins if they pick at least 2 balls of the same color, Player 2 wins if they pick at least 3 balls of the same color, and so on.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe approach I think of is as follows:\n\nFor each player\'s pick, we need to count how many times they picked a ball of the same color.\nWe can store this information in a HashMap, where the key is a combination of the player\'s index and the color of the ball they picked (e.g., [player,color]), and the value is the number of times that player has picked that color.\nFor example, in the input [[0,0],[1,0],[1,0],[2,1],[2,1],[2,0]]:\n\nWe store [0,0] in the HashMap, indicating Player 0 picked color 0 once.\nNext, we store [1,0] twice in the HashMap, indicating Player 1 picked color 0 two times.\nFor Player 2, we store [2,1] twice and [2,0] once in the HashMap.\nNow, to determine the winners:\n\nWe check if the number of balls a player has picked of any color is greater than or equal to the number they need to win. For Player 1, if they picked a color twice, they win because they need to pick at least two balls of the same color.\nIf the count satisfies the win condition for any player, we increase the count of winning players.\n \n# Code\n```java []\nclass Solution {\n    public int winningPlayerCount(int n, int[][] pick) {\n         HashMap<String,Integer> hm = new HashMap<>();\n         for(int i=0;i<pick.length;i++){\n            int fi = pick[i][0];\n            int se = pick[i][1];\n            String key = fi+","+se;\n            hm.put(key,hm.getOrDefault(key,0)+1);\n         }\n         int ans=0;\n         for(int i=0;i<n;i++){\n            boolean flag = false;\n            for(String key:hm.keySet()){\n                String part[] = key.split(",");\n                int a = Integer.parseInt(part[0]);\n                int val = hm.get(key);\n                if(a==i && val>i){\n                    flag=true;\n                    break;\n                }\n            }\n            if(flag){\n                ans++;\n            }\n         }\n         return ans;\n    }\n}\n```
['Java']