Subsets & Combinations - Count Number of Max Bitwise-OR Subsets
Identify the bug in the following code snippet for counting max bitwise-OR subsets:
from typing import List
class Solution:
def countMaxOrSubsets(self, nums: List[int]) -> int:
n = len(nums)
max_or = 0
count = 0
for mask in range(0, 1 << n): # Note: starts from 0
current_or = 0
for i in range(n):
if mask & (1 << i):
current_or |= nums[i]
if current_or > max_or:
max_or = current_or
count = 1
elif current_or == max_or:
count += 1
return count
