Skip to content
LC-2917 Easy LeetCode

2917. Find the K-or of an Array

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 72% Topics: Array, Bit Manipulation
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(nlogr)
# Space: O(1)

# bit manipulation
class Solution(object):
    def findKOr(self, nums, k):
        """
        :type nums: List[int]
        :type k: int
        :rtype: int
        """
        return sum(1<<i for i in xrange(max(nums).bit_length()) if sum((x&(1<<i)) != 0 for x in nums) >= k)

Solution from kamyu104/LeetCode-Solutions · MIT