1738. Find Kth Largest XOR Coordinate Value

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1738

class Solution:
    def kthLargestValue(self, matrix: List[List[int]], k: int) -> int:
        m, n = len(matrix), len(matrix[0])
        s = [[0] * (n + 1) for _ in range(m + 1)]
        res = []
        for i in range(m):
            for j in range(n):
                s[i + 1][j + 1] = s[i + 1][j] ^ s[i][j + 1] ^ s[i][j] ^ matrix[i][j]
                res.append(s[i + 1][j + 1])
        return nlargest(k, res)[-1]