Solve Leetcode Problems and Get Offers From Your Dream Companies
1738. Find Kth Largest XOR Coordinate Value (Weekly Contest 225)
Here I will solve problems from Leetcode contests. Today we will do the Find Kth Largest XOR Coordinate Value problem Weekly Contest 225.
Motivation to learn algorithms
Problem Statement
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 the 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:
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…