1738. Find Kth Largest XOR Coordinate Value
Description
You are given a 2D matrix
of size m x n
, consisting of non-negative integers. You are also given an integer k
.
The value of coordinate (a, b)
of the matrix is the XOR of all matrix[i][j]
where 0 <= i <= a < m
and 0 <= j <= b < n
(0-indexed).
Find the kth
largest value (1-indexed) of all the coordinates of matrix
.
Example 1:
Example 2:
Example 3:
Example 4:
Constraints:
m == matrix.length
n == matrix[i].length
1 <= m, n <= 1000
0 <= matrix[i][j] <= 106
1 <= k <= m * n
Tags
Array
Solution
Compute 2D prefix-xor;
Reshape it to 1D array and get the largest Kth element.
Complexity
Time complexity:
Space complexity:
Code
Reference
Previous1734. Decode XORed PermutationNext1744. Can You Eat Your Favorite Candy on Your Favorite Day?
Last updated
Was this helpful?