Find the K-or of an Array
You are given an integer array nums, and an integer k. Let's introduce K-or operation by extending the standard bitwise OR. In K-or, a bit position in the result is set to 1 if at least k numbers in nums have a 1 in that position.
Return the K-or of nums.
Example 1
Input
nums = [7,12,9,8,9,15], k = 4Output
9Bits 0 and 3 are each set in at least 4 numbers, so the result is
(1001)2 = 9.Example 2
Input
nums = [2,12,1,11,4,5], k = 6Output
0No bit appears as 1 in all six array numbers, as required for K-or with
k = 6, so the result is 0.Constraints
- 1 <= nums.length <= 50
- 0 <= nums[i] < 2^31
- 1 <= k <= nums.length