#1738
Find Kth Largest XOR Coordinate Value
specialist · 660 · lc medium +30 · premium · verified · 64.2% accepted · 539 likes · top 67%
Description
You are given a 2D matrix of non-negative integers and an integer k. The value at coordinate (a, b) is the XOR of all matrix[i][j] for 0 <= i <= a, 0 <= j <= b. Return the kth largest value (1-indexed) among all coordinate values.
Example 1:
Input: matrix = [[5,2],[1,6]], k = 1
Output: 7
Explanation: The value of coordinate (0,1) is 5 XOR 2 = 7, which is the largest value.
Example 2:
Input: matrix = [[5,2],[1,6]], k = 2
Output: 5
Explanation: The value of coordinate (0,0) is 5 = 5, which is the 2nd largest value.
Example 3:
Input: matrix = [[5,2],[1,6]], k = 3
Output: 4
Explanation: The value of coordinate (1,0) is 5 XOR 1 = 4, which is the 3rd largest value.
Code
1
2
3