1738. Find Kth Largest XOR Coordinate Value
On This Page
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]