Scala FP: sorting (actually even unnecessary), not using edges
Code\n\nobject Solution {\n  def maximumValueSum(nums: Array[Int], k: Int, edges: Array[Array[Int]]): Long = {\n    val nProfit = nums.map(n => n -> ((n ^ k) - 
# Code\n```\nobject Solution {\n  def maximumValueSum(nums: Array[Int], k: Int, edges: Array[Array[Int]]): Long = {\n    val nProfit = nums.map(n => n -> ((n ^ k) - n)).sortBy(-_._2)\n    val evenCount = nProfit.count(_._2 > 0) / 2 * 2\n    val xorCount = if (evenCount + 2 <= nums.length && nProfit(evenCount)._2 + nProfit(evenCount + 1)._2 > 0) evenCount + 2 else evenCount\n\n    nProfit.indices.foldLeft(0L)((sum, i) => sum + (if (i < xorCount) nProfit(i)._1 ^ k else nProfit(i)._1))\n  }\n}\n```
['Scala']