2419. Longest Subarray With Maximum Bitwise AND
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 62% Topics: Array, Bit Manipulation, Brainteaser
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
# bit manipulation
class Solution(object):
def longestSubarray(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
mx = max(nums)
result, l = 1, 0
for x in nums:
if x == mx:
l += 1
result = max(result, l)
else:
l = 0
return result
Solution from kamyu104/LeetCode-Solutions · MIT