Skip to content
LC-0898 Medium LeetCode

898. Bitwise ORs of Subarrays

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 41% Topics: Array, Dynamic Programming, Bit Manipulation
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(32 * n)
# Space: O(1)

class Solution(object):
    def subarrayBitwiseORs(self, A):
        """
        :type A: List[int]
        :rtype: int
        """
        result, curr = set(), {0}
        for i in A:
            curr = {i} | {i | j for j in curr}
            result |= curr
        return len(result)

Solution from kamyu104/LeetCode-Solutions · MIT