5. Find Kth Largest XOR Coordinate Value
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
.
Solution:
Approach: Step 1: Change the matrix so that matrix[i][j] will contain the xor of all the numbers in the ith row upto jth column as shown below.
Step 2: Change the above created matrix so that matrix[i][j] will contain the xor of all the numbers in the jth column upto ith row as shown below.
Time Complexity : O(NM logK)
Last updated