Beats 100% Video Solution | Java C++ Python
\n\nPython Beats 100%\n\n\n\nclass Solution {\n    public long maximumValueSum(int[] nums, int k, int[][] edges) {\n        \n        int n = nums.length;\n    
<iframe width="560" height="315" src="https://www.youtube.com/embed/Wo-MsfKNoq4?si=EZxKeHwSqgw4VtTY" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>\n\nPython Beats 100%\n\n\n```\nclass Solution {\n    public long maximumValueSum(int[] nums, int k, int[][] edges) {\n        \n        int n = nums.length;\n        Integer [] diff = new Integer[n];\n        long sum = 0;\n        for(int i = 0;i<n;i++){\n            diff[i] = (nums[i]^k)-nums[i];\n            sum+=nums[i];\n        }\n        \n        Arrays.sort(diff, Collections.reverseOrder());\n        \n        for(int i = 0;i<n;i+=2){\n            if(i+1 == n) return sum;\n            int pair = diff[i]+diff[i+1];\n            if(pair>0)sum+=pair;\n        }\n        return sum;\n    }\n}\n```\n\n```\nclass Solution {\npublic:\n    long maximumValueSum(std::vector<int>& nums, int k, std::vector<std::vector<int>>& edges) {\n        int n = nums.size();\n        std::vector<int> diff(n);\n        long sum = 0;\n\n        for (int i = 0; i < n; ++i) {\n            diff[i] = (nums[i] ^ k) - nums[i];\n            sum += nums[i];\n        }\n\n        std::sort(diff.begin(), diff.end(), std::greater<int>());\n\n        for (int i = 0; i < n; i += 2) {\n            if (i + 1 == n) return sum;\n            int pair = diff[i] + diff[i + 1];\n            if (pair > 0) sum += pair;\n        }\n\n        return sum;\n    }\n};\n```\n```\nclass Solution:\n    def maximumValueSum(self, nums, k, edges):\n        n = len(nums)\n        diff = [0] * n\n        total_sum = sum(nums)\n        \n        for i in range(n):\n            diff[i] = (nums[i] ^ k) - nums[i]\n        \n        diff.sort(reverse=True)\n        \n        for i in range(0, n, 2):\n            if i + 1 == n:\n                return total_sum\n            pair_sum = diff[i] + diff[i + 1]\n            if pair_sum > 0:\n                total_sum += pair_sum\n        \n        return total_sum\n\n```
['C', 'Python', 'Java']