Bitwise ORs of Subarrays LeetCode solution in Python
1class Solution:2def subarrayBitwiseORs(self, arr: List[int]) -> int:34ans = set(arr)56# each element is a subarry78one = set()910# to get the ans for the subarray of size >111# starting from 0th element to the ending element1213one.add(arr[0])1415for i in range(1, len(arr)):1617two = set()1819for j in one:2021two.add(j | arr[i])2223# subarray from the element in one set to the current ele(i th one)2425ans.add(j | arr[i])2627two.add(arr[i])2829# adding curr element to set two so that from next iteration we can take sub array starting from curr element3031one = two3233return len(ans)