Kotlin Solution
Intuition\nEssentially what they\'re asking for is the max sum of a node plus up to k of it\'s neighbors.\n\n# Approach\nI started by building a graph, but real
# Intuition\nEssentially what they\'re asking for is the max sum of a node plus up to k of it\'s neighbors.\n\n# Approach\nI started by building a graph, but realized if I stored them in a list or set, I would have to sort the neighbors later to grab the largest k of them greater than 0. Since rather than navigating the graph, we just need to visit every node a single time, we can store neighbors in a MaxHeap, so they\'re already sorted, and removing them from the heap while processing each node won\'t cause any problems\n\n# Complexity\n- Time complexity:\n$$O(v + eloge)$$ to build the map because heap insertions, and $$O(v * k)$$ to get the max sum, but if k is treated like a constant here, building the map should be the bottleneck.\n\n- Space complexity:\nSomething like $$O(v + e)$$ I guess, for the keys and values in the map. Clearly maps have some overhead inherent in the implementation.\n\n# Code\n```\nclass Solution {\n    fun maxStarSum(vals: IntArray, edges: Array<IntArray>, k: Int): Int {\n        val map = buildMap(vals, edges)\n\n        var maxSum = Integer.MIN_VALUE\n\n        map.forEach { entry ->\n            var sum = vals[entry.key]\n            val neighbors = entry.value\n            var edges = 0\n\n            for (i in 0 until k) {\n                if (neighbors.isEmpty() || neighbors.peek() <= 0) {\n                    break\n                }\n                sum += neighbors.remove()\n            }\n            maxSum = maxOf(maxSum, sum)\n        }\n\n        return maxSum\n    }\n\n    fun buildMap(vals: IntArray, edges: Array<IntArray>): Map<Int, PriorityQueue<Int>> {\n        val map = mutableMapOf<Int, PriorityQueue<Int>>()\n        \n        for (i in 0 until vals.size) {\n            map[i] = PriorityQueue<Int>(compareByDescending { it })\n        }\n\n        edges.forEach { edge ->\n            map[edge[0]]?.add(vals[edge[1]])\n            map[edge[1]]?.add(vals[edge[0]])\n        }\n\n        return map\n    }\n}\n```
['Heap (Priority Queue)', 'Kotlin']