O(N*M) Solution - Average Case
IntuitionCan we find XOR at (i,j) through precomputation? Answer is yes.
Relation would be matrix[i][j] = matrix[i][j] ^ matrix[i][j-1] ^ matrix[i-1][j] ^ matri
# Intuition
Can we find XOR at (i,j) through precomputation? Answer is yes.
Relation would be matrix[i][j] = matrix[i][j] ^ matrix[i][j-1] ^ matrix[i-1][j] ^ matrix[i-1][j-1].
Similar relation would work for $$+$$ operator as well.

# Approach
Once you have the above formulae you can calculate XOR of matrix[i][j]. All that is left is finding kth largest we can use quick select algorithm. I have taken advantage of cpp here.

If you dont want to use quick select. Use vector and insert with binary search complexity would increase for last operation to n*log(k). Still overall complexity would be O(n*m). 
But space complexity would be reduced to O(k).

# Complexity
- Time complexity:
$$O(n*m)$$

- Space complexity:
$$O(n)$$ because of vector.

# Code
```cpp []
class Solution {
public:
    int kthLargestValue(vector<vector<int>>& matrix, int k) {
        int row = matrix.size();
        int col = matrix[0].size();
        vector<int> values;
        for(int i=0;i<row;i++) {
            for(int j=0;j<col;j++) {
                if (i > 0) {
                    matrix[i][j] ^= matrix[i-1][j];
                }
                if (j > 0) {
                    matrix[i][j] ^= matrix[i][j-1];
                }
                if (i&&j) {
                    matrix[i][j] ^= matrix[i-1][j-1];
                }
                values.push_back(matrix[i][j]);
            }
        }

        nth_element(values.begin(), values.begin()+k-1, values.end(), greater<int>());

        return values[k-1];
    }
};

/**

5 2 4
1 4 2
8 2 5
**/
```
['C++']