Easy JAVA Solution using Greedy Approach with intuition beats 100%
Intuition\n Describe your first thoughts on how to solve this problem. \nKey Observations:-\n- xor only those node\'s value with k which gives a result>node val
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nKey Observations:-\n- xor only those node\'s value with k which gives a result>node val(nums[i]^k>nums[i])\n- we can choose any pair of nodes and xor them beacuase all are connected(indirectly & no. of edges=n-1).\n- we need to count for how many nodes we have performed the xor value,if the count is odd, then we have to perform xor on one more node which gives the minLoss(Math.abs(nums[i]-nums[i]^k)).\n- If the count is even, we add all the xor values with the original values of those node which we didn\'t perform xor.\n- If the count is odd, we return the sum subtracted by the minLoss.\n\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public long maximumValueSum(int[] nums, int k, int[][] edges) {\n       long sum=0;\n       int cnt=0;\n       int min_Loss=Integer.MAX_VALUE;\n       for(int it:nums){\n            if((it^k)>it){\n                cnt++;\n                sum+=it^k;\n            }\n            else\n            sum+=it;\n            min_Loss=Math.min(min_Loss,Math.abs(it-(it^k)));\n       } \n       if(cnt%2==1){\n        return sum-min_Loss;\n       }\n       else\n       return sum;\n    }\n}\n```
['Greedy', 'Tree', 'Graph', 'Java']