Longest Subarray With Maximum Bitwise AND (Leetcode 2419)

Problem Link: https://leetcode.com/contest/weekly-contest-312/problems/longest-subarray-with-maximum-bitwise-and/

class Solution:
    def longestSubarray(self, nums: List[int]) -> int:
        
        # Find the length of largest continuos array of 
        # maxx integers
        n=len(nums)
        m=max(nums)
        ans=-1
        c=0
        for i in nums:
            if(i==m):
                c+=1
                ans=max(ans,c)
            else:
                c=0
            
        return ans  

Last updated