Pick (or) Not-Pick || Damn Easy Solution
Approach\n\n- DFS\n- flag_index is the state of the current node.\n- If the current_index is picked then the flag_index is flipped to indicate the change of sta
# Approach\n\n- DFS\n- ```flag_index``` is the state of the current node.\n- If the ```current_index``` is picked then the ```flag_index``` is flipped to indicate the change of state of the node.\n\n# Complexity\n\n- Time complexity : $$O(N)$$\n\n- Space complexity : $$O(H)$$\n\n# Code\n\n```\nclass Solution {\n\n    public long depth_first_search(int K , int flag_index , int current_index , int N , int[] array , Long[][] dp_matrix){\n\n        if(current_index >= N){\n            return ((flag_index == 0) ? (0) : (Integer.MIN_VALUE));\n        }\n\n        if(dp_matrix[current_index][flag_index] != null){\n            return dp_matrix[current_index][flag_index];\n        }\n\n        long pick = ((array[current_index] ^ K) + depth_first_search(K , ((flag_index + 1) % 2) , (current_index + 1) , N , array , dp_matrix));\n\n        long not_pick = (array[current_index] + depth_first_search(K , flag_index , (current_index + 1) , N , array , dp_matrix));\n\n        dp_matrix[current_index][flag_index] = Math.max(pick , not_pick);\n\n        return dp_matrix[current_index][flag_index];\n    }\n\n    public long maximumValueSum(int[] array , int K , int[][] edges_details_matrix){\n        \n        int N = array.length;\n\n        return depth_first_search(K , 0 , 0 , N , array , (new Long[N][2]));\n    }\n}\n```
['Dynamic Programming', 'Depth-First Search', 'Recursion', 'Memoization', 'Java']