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
Inputnums = [7,12,9,8,9,15], k = 4
Output9
Bits 0 and 3 are each set in at least 4 numbers, so the result is (1001)2 = 9.
Example 2
Inputnums = [2,12,1,11,4,5], k = 6
Output0
No 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

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate