💥 Memory beats 100% [EXPLAINED]
IntuitionThe problem asks for finding the maximum value sum based on a sequence of numbers where you can either choose the number as is or apply a bitwise XOR o
# Intuition
The problem asks for finding the maximum value sum based on a sequence of numbers where you can either choose the number as is or apply a bitwise XOR operation with a given constant k. The XOR operation flips the bits of the number and may change its value, so we need to decide whether to include the number as is or apply XOR based on the current state (even or odd index).

# Approach
We use dynamic programming to solve this problem, where dp[index][isEven] stores the maximum value obtainable from the index position onward, given whether the current state is even or odd. Starting from the first index, we can either take the number as is or apply XOR with k, and for each decision, we recursively calculate the result for the next index, updating the DP table to avoid redundant calculations. At the base case, if we've processed all numbers, we return 0 for the even state or a very small value for the odd state.

# Complexity
- Time complexity:
O(n) where n is the number of elements in the array nums. Each index is processed once, and for each, we only do constant-time operations (max calculation and recursion).

- Space complexity:
O(n) for storing the DP table, where n is the length of nums. The space is used to memoize the results for each state at each index.

# Code
```kotlin []
class Solution {
    fun maximumValueSum(nums: IntArray, k: Int, edges: Array<IntArray>): Long {
        val dp = Array(nums.size) { LongArray(2) { -1L } }
        return dfs(nums, k, edges, 0, 1, dp)
    }

    private fun dfs(nums: IntArray, k: Int, edges: Array<IntArray>, index: Int, isEven: Int, dp: Array<LongArray>): Long {
        if (index == nums.size) {
            return if (isEven == 1) 0 else Long.MIN_VALUE
        }
        if (dp[index][isEven] != -1L) {
            return dp[index][isEven]
        }

        val val1 = nums[index] + dfs(nums, k, edges, index + 1, isEven, dp)
        val val2 = (nums[index] xor k) + dfs(nums, k, edges, index + 1, isEven xor 1, dp)

        dp[index][isEven] = maxOf(val1, val2)
        return dp[index][isEven]
    }
}

```
['Math', 'Dynamic Programming', 'Backtracking', 'Greedy', 'Bit Manipulation', 'Depth-First Search', 'Graph', 'Binary Search Tree', 'Sorting', 'Kotlin']