[Python3] 79ms, beats 100%
Background\nI know this is briefly explained but I want to share this code as it gets better results than other solutions I\'ve seen here (79ms, beats 100% of p
# Background\nI know this is briefly explained but I want to share this code as it gets better results than other solutions I\'ve seen here (79ms, beats 100% of people).\nThe code should be relatively understandable, at least after looking at other solutions\n\n# Intuition\nTo solve the problem as quickly as possible we need to be able to OR the entire array as quickly as possible, and not to waste time on values that are too small to be relevant.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nTo start, we find a power of 2 of which smaller values are not even worth checking.\nThen, we want to quickly be able to find the OR of the suffix - the entire array from a specific point onwards.\nAt last, we want to occumulate the OR the same way to find the prefix OR result.\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n```python3 []\nclass Solution:\n    def maximumOr(self, nums: List[int], k: int) -> int:\n        result=0\n        min_relevant = 2**floor(math.log2(max(nums)))\n\n        or_occumulating = 0\n        suffix_or = [0]*(len(nums))\n        for i in range(len(nums)-1, 0, -1):\n            suffix_or[i-1] = or_occumulating = or_occumulating | nums[i]\n        or_occumulating = 0\n        for i in range(len(nums)):\n            if nums[i] >= min_relevant:\n                result = max(\n                    result,\n                    (nums[i] << k) | or_occumulating | suffix_or[i]\n                )\n            or_occumulating |= nums[i]\n        return result\n```
['Python3']