JS/TS Iterative Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n## Time
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n## Time complexity:\n- The time complexity of this function is O(nlogn), where n is the number of nodes in the graph. This is because we iterate through each node in the graph and sort its neighbors in descending order, which takes O(logn) time for each node\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n## Space complexity:\n- The space complexity is O(n), where n is the number of nodes in the graph. This is because we use a map to store the adjacency list of the graph, which takes up O(n) space.\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```javascript []\n/**\n * @param {number[]} vals\n * @param {number[][]} edges\n * @param {number} k\n * @return {number}\n */\nvar maxStarSum = function (vals, edges, k) {\n    let maxSum = -Infinity;\n\n    let adjList = new Map();\n\n    for (let [a, b] of edges) {\n        if (!adjList.has(a)) adjList.set(a, []);\n        if (!adjList.has(b)) adjList.set(b, []);\n\n        adjList.get(a).push(vals[b]);\n        adjList.get(b).push(vals[a]);\n    }\n\n    for (let i = 0; i < vals.length; i++) {\n        let neighbours = adjList.get(i) || [];\n\n        neighbours.sort((a, b) => b - a);\n        let sum = vals[i];\n\n        for (let j = 0; j < Math.min(k, neighbours.length); j++) {\n            if (neighbours[j] > 0) sum += neighbours[j];\n        }\n\n        maxSum = Math.max(sum, maxSum);\n    }\n\n    return maxSum;\n};\n```
['Graph', 'Sorting', 'TypeScript', 'JavaScript']