✅✅ MAP SOLUTION ON JS/TS Beats 92.65% ✅✅
Approach\n Describe your approach to solving the problem. \nWe need to go through all the picks and create a new structure to calculate the count of colors by p
# Approach\n<!-- Describe your approach to solving the problem. -->\nWe need to go through all the picks and create a new structure to calculate the count of colors by player.\n\n![image.png](https://assets.leetcode.com/users/images/f3fd5df7-eec0-441b-be0a-425d5ea3bb01_1727354699.1993399.png)\n\n\n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```typescript []\nfunction winningPlayerCount(n: number, pick: number[][]): number {\n    const players = new Set();\n\n    const map = new Map<number, Map<number, number>>();\n\n    for (const [player, color] of pick) {\n        if (players.has(player)) {\n            continue;\n        }\n\n        if (!map.has(player)) {\n            map.set(player, new Map<number, number>());\n        }\n\n        const colorsMap = map.get(player);\n        const colorCount = (colorsMap.get(color) || 0) + 1;\n        if (colorCount > player) {\n            players.add(player);\n        }\n        colorsMap.set(color, colorCount);\n    }\n\n    return players.size;\n};\n\n```\n\n\n# Code\n```javascript []\n/**\n * @param {number} n\n * @param {number[][]} pick\n * @return {number}\n */\nvar winningPlayerCount = function (n, pick) {\n    const players = new Set();\n\n    const map = new Map();\n\n    for (const [player, color] of pick) {\n        if (players.has(player)) {\n            continue;\n        }\n\n        if (!map.has(player)) {\n            map.set(player, new Map());\n        }\n\n        const colorsMap = map.get(player);\n        const colorCount = (colorsMap.get(color) || 0) + 1;\n        if (colorCount > player) {\n            players.add(player);\n        }\n        colorsMap.set(color, colorCount);\n    }\n\n    return players.size;\n};\n\n\n```
['Hash Table', 'Counting', 'TypeScript', 'JavaScript']