JS | TS | O(mn) | O(1) | 100% | 100%
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nIt uses bottom-up dynamic programming approach to calculate the XOR value
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nIt uses bottom-up dynamic programming approach to calculate the XOR values in-place, transformiing the original matrix into the preprocessed matrix ( thats why the TC is O(1) ).\nThen it uses [quick-select](https://www.geeksforgeeks.org/quickselect-algorithm/) with [hoare-partition-scheme](https://stackoverflow.com/questions/58331986/quickselect-with-hoare-partition-scheme) to find the Kth element.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(mn)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nfunction kthLargestValue(matrix: number[][], k: number): number {\n    const r = matrix.length;\n    const c = matrix[0].length;\n    const x = r * c;\n\n    for (let i = 0; i < r; i++) {\n        for (let j = 0; j < c; j++) {\n            matrix[i][j] ^= (matrix[i - 1]?.[j - 1] ?? 0) ^ (matrix[i - 1]?.[j] ?? 0) ^ (matrix[i][j - 1] ?? 0);\n        }\n    }\n\n    k -= 1;\n\n    const getValueAt = (i: number) => matrix[~~(i / c)][i % c];\n    const swap = (i: number, j: number) => {\n        const t = matrix[~~(i / c)][i % c];\n        matrix[~~(i / c)][i % c] = matrix[~~(j / c)][j % c];\n        matrix[~~(j / c)][j % c] = t;\n    }\n\n    // https://stackoverflow.com/questions/58331986/quickselect-with-hoare-partition-scheme\n    const partition = (l: number, h: number): number => {\n        if (l === h) return l;\n\n        const o = getValueAt(l);\n        let i = l;\n        let j = h + 1;\n\n        while (true) {\n            do {\n                i++;\n            } while (i < x && getValueAt(i) > o);\n            do {\n                j--;\n            } while (getValueAt(j) < o);\n\n            if (i >= j) {\n                swap(l, j);\n\n                return j;\n            }\n            else swap(i, j);\n        }\n    };\n    const quickSelect = (l: number, h: number): number => {\n        while (l < h) {\n            const p = partition(l, h);\n\n            if (p === k) return getValueAt(p);\n            else if (k < p) h = p - 1;\n            else l = p + 1;\n        }\n\n        return getValueAt(l);\n\n    };\n\n    return quickSelect(0, x - 1);\n};\n```
['Dynamic Programming', 'Quickselect', 'TypeScript', 'JavaScript']