Algorithms
Easy
2917
3183
Find the K-or of an Array
find-the-k-or-of-an-array
"""
You are given a 0-indexed integer array nums, and an integer k.

The K-or of nums is a non-negative integer that satisfies the following:

 * The ith bit is set in the K-or if and only if there are at least k elements of nums in which bit i is set.

Return the K-or of nums.

Note that a bit i is set in x if (2i AND x) == 2i, where AND is the bitwise AND operator.

Example 1:

Input: nums = [7,12,9,8,9,15], k = 4
Output: 9
Explanation: Bit 0 is set at nums[0], nums[2], nums[4], and nums[5].
Bit 1 is set at nums[0], and nums[5].
Bit 2 is set at nums[0], nums[1], and nums[5].
Bit 3 is set at nums[1], nums[2], nums[3], nums[4], and nums[5].
Only bits 0 and 3 are set in at least k elements of the array, and bits i >= 4 are not set in any of the array's elements. Hence, the answer is 2^0 + 2^3 = 9.

Example 2:

Input: nums = [2,12,1,11,4,5], k = 6
Output: 0
Explanation: Since k == 6 == nums.length, the 6-or of the array is equal to the bitwise AND of all its elements. Hence, the answer is 2 AND 12 AND 1 AND 11 AND 4 AND 5 = 0.

Example 3:

Input: nums = [10,8,5,9,11,6,8], k = 1
Output: 15
Explanation: Since k == 1, the 1-or of the array is equal to the bitwise OR of all its elements. Hence, the answer is 10 OR 8 OR 5 OR 9 OR 11 OR 6 OR 8 = 15.


Constraints:

 * 1 <= nums.length <= 50
 * 0 <= nums[i] < 231
 * 1 <= k <= nums.length
"""
class Solution:
    def findKOr(self, nums: List[int], k: int) -> int:
        
You are given a 0-indexed integer array nums, and an integer k.

The K-or of nums is a non-negative integer that satisfies the following:

 * The ith bit is set in the K-or if and only if there are at least k elements of nums in which bit i is set.

Return the K-or of nums.

Note that a bit i is set in x if (2i AND x) == 2i, where AND is the bitwise AND operator.

Example 1:

Input: nums = [7,12,9,8,9,15], k = 4
Output: 9
Explanation: Bit 0 is set at nums[0], nums[2], nums[4], and nums[5].
Bit 1 is set at nums[0], and nums[5].
Bit 2 is set at nums[0], nums[1], and nums[5].
Bit 3 is set at nums[1], nums[2], nums[3], nums[4], and nums[5].
Only bits 0 and 3 are set in at least k elements of the array, and bits i >= 4 are not set in any of the array's elements. Hence, the answer is 2^0 + 2^3 = 9.

Example 2:

Input: nums = [2,12,1,11,4,5], k = 6
Output: 0
Explanation: Since k == 6 == nums.length, the 6-or of the array is equal to the bitwise AND of all its elements. Hence, the answer is 2 AND 12 AND 1 AND 11 AND 4 AND 5 = 0.

Example 3:

Input: nums = [10,8,5,9,11,6,8], k = 1
Output: 15
Explanation: Since k == 1, the 1-or of the array is equal to the bitwise OR of all its elements. Hence, the answer is 10 OR 8 OR 5 OR 9 OR 11 OR 6 OR 8 = 15.


Constraints:

 * 1 <= nums.length <= 50
 * 0 <= nums[i] < 231
 * 1 <= k <= nums.length


Please complete the code below to solve above prblem:
```python
class Solution:
    def findKOr(self, nums: List[int], k: int) -> int:
        
```

my_solution = Solution()

test_input = { "nums": [7,12,9,8,9,15], "k": 4 }
assert my_solution.findKOr(**test_input) == 9

test_input = { "nums": [2,12,1,11,4,5], "k": 6 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [10,8,5,9,11,6,8], "k": 1 }
assert my_solution.findKOr(**test_input) == 15

test_input = { "nums": [14,7,12,9,8,9,1,15], "k": 4 }
assert my_solution.findKOr(**test_input) == 13

test_input = { "nums": [2,12,1,11,4,5], "k": 3 }
assert my_solution.findKOr(**test_input) == 5

test_input = { "nums": [10,8,5,10,11,11,6,8], "k": 1 }
assert my_solution.findKOr(**test_input) == 15

test_input = { "nums": [0], "k": 1 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [1], "k": 1 }
assert my_solution.findKOr(**test_input) == 1

test_input = { "nums": [2], "k": 1 }
assert my_solution.findKOr(**test_input) == 2

test_input = { "nums": [3], "k": 1 }
assert my_solution.findKOr(**test_input) == 3

test_input = { "nums": [4], "k": 1 }
assert my_solution.findKOr(**test_input) == 4

test_input = { "nums": [5], "k": 1 }
assert my_solution.findKOr(**test_input) == 5

test_input = { "nums": [6], "k": 1 }
assert my_solution.findKOr(**test_input) == 6

test_input = { "nums": [7], "k": 1 }
assert my_solution.findKOr(**test_input) == 7

test_input = { "nums": [8], "k": 1 }
assert my_solution.findKOr(**test_input) == 8

test_input = { "nums": [9], "k": 1 }
assert my_solution.findKOr(**test_input) == 9

test_input = { "nums": [10], "k": 1 }
assert my_solution.findKOr(**test_input) == 10

test_input = { "nums": [11], "k": 1 }
assert my_solution.findKOr(**test_input) == 11

test_input = { "nums": [12], "k": 1 }
assert my_solution.findKOr(**test_input) == 12

test_input = { "nums": [13], "k": 1 }
assert my_solution.findKOr(**test_input) == 13

test_input = { "nums": [14], "k": 1 }
assert my_solution.findKOr(**test_input) == 14

test_input = { "nums": [15], "k": 1 }
assert my_solution.findKOr(**test_input) == 15

test_input = { "nums": [16], "k": 1 }
assert my_solution.findKOr(**test_input) == 16

test_input = { "nums": [17], "k": 1 }
assert my_solution.findKOr(**test_input) == 17

test_input = { "nums": [18], "k": 1 }
assert my_solution.findKOr(**test_input) == 18

test_input = { "nums": [19], "k": 1 }
assert my_solution.findKOr(**test_input) == 19

test_input = { "nums": [20], "k": 1 }
assert my_solution.findKOr(**test_input) == 20

test_input = { "nums": [21], "k": 1 }
assert my_solution.findKOr(**test_input) == 21

test_input = { "nums": [22], "k": 1 }
assert my_solution.findKOr(**test_input) == 22

test_input = { "nums": [23], "k": 1 }
assert my_solution.findKOr(**test_input) == 23

test_input = { "nums": [24], "k": 1 }
assert my_solution.findKOr(**test_input) == 24

test_input = { "nums": [25], "k": 1 }
assert my_solution.findKOr(**test_input) == 25

test_input = { "nums": [26], "k": 1 }
assert my_solution.findKOr(**test_input) == 26

test_input = { "nums": [27], "k": 1 }
assert my_solution.findKOr(**test_input) == 27

test_input = { "nums": [28], "k": 1 }
assert my_solution.findKOr(**test_input) == 28

test_input = { "nums": [29], "k": 1 }
assert my_solution.findKOr(**test_input) == 29

test_input = { "nums": [30], "k": 1 }
assert my_solution.findKOr(**test_input) == 30

test_input = { "nums": [31], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [22,7,27,30,15,30,28], "k": 4 }
assert my_solution.findKOr(**test_input) == 30

test_input = { "nums": [24,18,3,23,16,11,27,18,5,29], "k": 6 }
assert my_solution.findKOr(**test_input) == 19

test_input = { "nums": [14,1,2,28,4,15,3,12], "k": 2 }
assert my_solution.findKOr(**test_input) == 15

test_input = { "nums": [7,18,25,11,2], "k": 5 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [0,4], "k": 2 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [17,5,14,16,24,30,3,19,31], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [14,20,23,7,1,12,24,19], "k": 7 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [5,31,29,22,8,6,23], "k": 4 }
assert my_solution.findKOr(**test_input) == 23

test_input = { "nums": [9,10,30,0,7,19,14,19,20,3], "k": 4 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [25,6,5,30,27,11,10,30], "k": 2 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [0,15,16,6,19,5,24,17], "k": 3 }
assert my_solution.findKOr(**test_input) == 23

test_input = { "nums": [19,8,2,28,4,5], "k": 5 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [13,9,1,15,9,2,19,19], "k": 3 }
assert my_solution.findKOr(**test_input) == 11

test_input = { "nums": [16,6,16,22,8,2,25,30], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [14,28,23,22], "k": 2 }
assert my_solution.findKOr(**test_input) == 30

test_input = { "nums": [6,26], "k": 2 }
assert my_solution.findKOr(**test_input) == 2

test_input = { "nums": [14,9,22,30,15], "k": 4 }
assert my_solution.findKOr(**test_input) == 14

test_input = { "nums": [12,13,16,25,12,4,8,29], "k": 6 }
assert my_solution.findKOr(**test_input) == 8

test_input = { "nums": [27,29], "k": 2 }
assert my_solution.findKOr(**test_input) == 25

test_input = { "nums": [9,27,27,20,24,13,25,8], "k": 6 }
assert my_solution.findKOr(**test_input) == 8

test_input = { "nums": [22,26,18,26,1], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [20,20,31,19,29,19], "k": 2 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [5,8,27,23,3], "k": 2 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [4,23,0,20,4,19,14,22,26,2], "k": 9 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [31,26,21,4,9,11,13,24,23,5], "k": 10 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [4,22], "k": 2 }
assert my_solution.findKOr(**test_input) == 4

test_input = { "nums": [22,17,20,3,21,5,20,25,16], "k": 4 }
assert my_solution.findKOr(**test_input) == 21

test_input = { "nums": [16,15,13,26,15,23,0,12], "k": 4 }
assert my_solution.findKOr(**test_input) == 15

test_input = { "nums": [4,11,14], "k": 1 }
assert my_solution.findKOr(**test_input) == 15

test_input = { "nums": [10,26,27,25,3,21,9,3,22], "k": 8 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [4,11,16], "k": 2 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [9,27,19,9,24,11], "k": 3 }
assert my_solution.findKOr(**test_input) == 27

test_input = { "nums": [29,19,27,14], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [27,31,21,8,25], "k": 2 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [14,1,13,22,27], "k": 5 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [14,15,17,23,29], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [19,21], "k": 2 }
assert my_solution.findKOr(**test_input) == 17

test_input = { "nums": [29,9,18,0,30,5,1,9], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [6,31,11,7,6,2,26,19,17,13], "k": 10 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [15,8,27,28], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [28,24,20,31,23,1], "k": 2 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [8,13,27,24,20,28,15,21,23,6], "k": 9 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [31,6], "k": 2 }
assert my_solution.findKOr(**test_input) == 6

test_input = { "nums": [3,14,11,17,9], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [14,11], "k": 2 }
assert my_solution.findKOr(**test_input) == 10

test_input = { "nums": [2,9,11,25,3,2,26,21,13,11], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [26,7,23,0,16,31,12,18,24], "k": 4 }
assert my_solution.findKOr(**test_input) == 30

test_input = { "nums": [11,30,30,17,10,27,6,31,0], "k": 4 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [11,9,18,30,27,20,2,17,18,4], "k": 2 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [2,1,0,30,29,14,13,26,10,22], "k": 10 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [21,30,30,17,23,8,26,9], "k": 6 }
assert my_solution.findKOr(**test_input) == 16

test_input = { "nums": [16,10], "k": 1 }
assert my_solution.findKOr(**test_input) == 26

test_input = { "nums": [26,12,19,22,5,6,19,30,24,11], "k": 10 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [20,10,14], "k": 2 }
assert my_solution.findKOr(**test_input) == 14

test_input = { "nums": [23,17,18,30,3], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [13,16,12], "k": 1 }
assert my_solution.findKOr(**test_input) == 29

test_input = { "nums": [17,12,5,13,23,19], "k": 3 }
assert my_solution.findKOr(**test_input) == 21

test_input = { "nums": [5,4,3], "k": 2 }
assert my_solution.findKOr(**test_input) == 5

test_input = { "nums": [6,28,1,3,2], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [28,3,15,30,10,29], "k": 4 }
assert my_solution.findKOr(**test_input) == 14

test_input = { "nums": [0,31,13,24,16,21], "k": 3 }
assert my_solution.findKOr(**test_input) == 29

test_input = { "nums": [11,20,28,29,3,4], "k": 2 }
assert my_solution.findKOr(**test_input) == 31