Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e2cc4cc

Browse files
committed
Add solution #1738
1 parent 2effdba commit e2cc4cc

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,511 LeetCode solutions in JavaScript
1+
# 1,512 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1339,6 +1339,7 @@
13391339
1735|[Count Ways to Make Array With Product](./solutions/1735-count-ways-to-make-array-with-product.js)|Hard|
13401340
1736|[Latest Time by Replacing Hidden Digits](./solutions/1736-latest-time-by-replacing-hidden-digits.js)|Easy|
13411341
1737|[Change Minimum Characters to Satisfy One of Three Conditions](./solutions/1737-change-minimum-characters-to-satisfy-one-of-three-conditions.js)|Medium|
1342+
1738|[Find Kth Largest XOR Coordinate Value](./solutions/1738-find-kth-largest-xor-coordinate-value.js)|Medium|
13421343
1748|[Sum of Unique Elements](./solutions/1748-sum-of-unique-elements.js)|Easy|
13431344
1749|[Maximum Absolute Sum of Any Subarray](./solutions/1749-maximum-absolute-sum-of-any-subarray.js)|Medium|
13441345
1752|[Check if Array Is Sorted and Rotated](./solutions/1752-check-if-array-is-sorted-and-rotated.js)|Easy|
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* 1738. Find Kth Largest XOR Coordinate Value
3+
* https://leetcode.com/problems/find-kth-largest-xor-coordinate-value/
4+
* Difficulty: Medium
5+
*
6+
* You are given a 2D matrix of size m x n, consisting of non-negative integers. You are also
7+
* given an integer k.
8+
*
9+
* The value of coordinate (a, b) of the matrix is the XOR of all matrix[i][j] where
10+
* 0 <= i <= a < m and 0 <= j <= b < n (0-indexed).
11+
*
12+
* Find the kth largest value (1-indexed) of all the coordinates of matrix.
13+
*/
14+
15+
/**
16+
* @param {number[][]} matrix
17+
* @param {number} k
18+
* @return {number}
19+
*/
20+
var kthLargestValue = function(matrix, k) {
21+
const rows = matrix.length;
22+
const cols = matrix[0].length;
23+
const xorValues = new Array(rows * cols);
24+
const prefixXor = Array.from({ length: rows + 1 }, () => Array(cols + 1).fill(0));
25+
26+
let index = 0;
27+
for (let i = 1; i <= rows; i++) {
28+
for (let j = 1; j <= cols; j++) {
29+
prefixXor[i][j] = prefixXor[i-1][j] ^ prefixXor[i][j-1]
30+
^ prefixXor[i-1][j-1] ^ matrix[i-1][j-1];
31+
xorValues[index++] = prefixXor[i][j];
32+
}
33+
}
34+
35+
xorValues.sort((a, b) => b - a);
36+
return xorValues[k-1];
37+
};

0 commit comments

Comments
 (0)