3183. Find the K-or of an Array
My accepted JavaScript solution to LeetCode problem 3183, Find the K-or of an Array, running in 2ms.
- Difficulty: Easy
- JavaScript
- Runtime 2ms
- Memory 57.7MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
JavaScript
Accepted on LeetCode — runtime 2ms, memory 57.7MB, accepted 2025-12-29.
/**
* @param {number[]} nums
* @param {number} k
* @return {number}
*/
var findKOr = function(nums, k) {
let result = 0;
for (let bit = 0; bit < 32; bit++) {
let count = 0;
for (const num of nums) {
if ((num >> bit) & 1) count++;
}
if (count >= k) result |= (1 << bit);
}
return result;
}