LeetCode: Find Kth Largest Xor Coordinate Value Solution
Approach
Accumulated XOR
Desc sort
Implementation
1var kthLargestValue = function (matrix, k) {2 let m = matrix[0].length3 let n = matrix.length45 for (let i = 0; i < n; i++) {6 for (let j = 0; j < m; j++) {7 const up = i - 1 < 0 ? 0 : matrix[i - 1][j]8 const left = j - 1 < 0 ? 0 : matrix[i][j - 1]9 const upleft = j - 1 < 0 || i - 1 < 0 ? 0 : matrix[i - 1][j - 1]10 matrix[i][j] ^= up ^ left ^ upleft11 }12 }1314 return matrix.flat().sort((a, b) => b - a)[k - 1]15}
Comments
Loading comments...
Tags
leetcode
Apply and earn a $2,500 bonus once you're hired on your first job!
Clients from the Fortune 500 to Silicon Valley startups
Choose your own rate, get paid on time
From hourly, part-time, to full-time positions
Flexible remote working environment
A lot of open JavaScript jobs!!
Fact corner: Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.
Still hesitate? Read HoningJS author's guide on dealing with Toptal interview process.