2025-08-22 10:37:11 +0000 UTC

Find the K-or of an Array

Code

class Solution:
    def findKOr(self, nums: List[int], k: int) -> int:
        freqs = [0] * 31
        for num in nums:
            i = 0    
            while num > 0:
                if num & 1 == 1:
                    freqs[i] += 1
                i += 1
                num >>= 1
        res = 0
        for i, freq in enumerate(freqs):
            if freq >= k:
                res |= 1 << i
        return res