O(N) approach | Easy | Tricky | C++ | Beat 100%
Intuition\nwe firstly check from the given nodes which gives me profit.  \nwe store nodes which gave us profit in x vector.\nand rest all to nx vector.\n\n# App
# Intuition\nwe firstly check from the given nodes which gives me profit.  \nwe store nodes which gave us profit in x vector.\nand rest all to nx vector.\n\n# Approach\n if size of x vector is EVEN than we can take XOR with all nodes because there will always exist 1 way to XOR them.\n\n\nbut if size is ODD than we have two options.\n        1. neglect node from x vector which have least PROFIT.\n        2. take node from nx vector which have lowest LOSS if exist.\n\n# Complexity\n- Time complexity:\n  n(logn)  but can we optimised to O(n) by not sorting x and nx array rather finding minimum of both array by ittrating it.\n\n- Space complexity:\nO(n)\n\n#                        NO Use of Edges (:\n\n# Code\n```\n#define ll long long int\nclass Solution {\npublic:\n    \n    long long maximumValueSum(vector<int>& nums, int k, vector<vector<int>>& e) {\n        \n        int n = nums.size();\n        ll ans  = 0;\n        ll sum1 = 0;\n        ll sum2 = 0;\n        vector<ll> x,nx;\n        \n        for(int i=0;i<n;i++){\n            int diff = ( nums[i]^k ) - nums[i];\n            \n            if( diff >= 0 ){\n                x.push_back( diff );\n                sum1 += ( nums[i]^k );\n            }\n            else{\n                nx.push_back( abs(diff) );\n                sum2 += nums[i];\n            }\n        }\n        \n        sort( x.begin() , x.end() );\n        sort( nx.begin(), nx.end() );\n        \n        if( x.size()%2 == 0 ){\n            ans = max( ans, sum1+sum2);   \n        }\n        else{\n            \n            if( nx.size() )\n                ans = max( sum1 + sum2 - x[0] , sum1 + sum2 - nx[0] );\n            else\n                ans = sum1 + sum2 - x[0];   \n        }\n        \n        return ans;\n    }\n};\n```
['Bit Manipulation', 'C++']