[JAVA] Quick select algorithm - O(n) avg performance
\nclass Solution {\n    \n    private static final Random RAND = new Random(0);\n    \n    public int kthLargestValue(int[][] matrix, int k) {\n        var xor 
```\nclass Solution {\n    \n    private static final Random RAND = new Random(0);\n    \n    public int kthLargestValue(int[][] matrix, int k) {\n        var xor = convertToXorArray(matrix);\n        var targetIdx = xor.length - k;\n        sortPartially(xor, targetIdx, 0, xor.length);\n        return xor[targetIdx];\n    }\n    \n    void sortPartially(int[] nums, int targetIdx, int origLo, int origHi) {\n        if (origHi - origLo < 2)\n            return;\n        \n        var pivotIdx = RAND.nextInt(origHi - origLo) + origLo;\n        var pivot = nums[pivotIdx];\n        swap(nums, origLo, pivotIdx);\n        \n        var lo = origLo;\n        var mid = lo + 1;\n        var hi = origHi;\n        while (mid < hi) {\n            if (pivot < nums[mid])\n                swap(nums, mid, --hi);\n            else if (pivot > nums[mid])\n                swap(nums, mid++, lo++);\n            else\n                mid++;\n        }\n        \n        if (targetIdx < lo)\n            sortPartially(nums, targetIdx, origLo, lo);\n        \n        sortPartially(nums, targetIdx, mid, origHi);\n    }\n    \n    void swap(int[] n, int p, int q) {\n        var tmp = n[p];\n        n[p] = n[q];\n        n[q] = tmp;\n    }\n    \n    int[] convertToXorArray(int[][] matrix) {\n        var rows = matrix.length;\n        var cols = matrix[0].length;\n        var xor = new int[rows * cols];\n        for (int r = 0; r < rows; r++) {\n            for (int c = 0; c < cols; c++) {\n                var xIdx = r * cols + c;\n                xor[xIdx] = matrix[r][c];\n                if (c > 0)\n                    xor[xIdx] ^= xor[xIdx - 1];\n            }\n        }\n\n        for (int i = cols; i < xor.length; i++)\n            xor[i] ^= xor[i - cols];\n\n        return xor;\n    }\n}\n```
['Java']