<p>You are given an integer array <code>nums</code> of size <code>n</code>.</p>

<p>Consider a <strong>non-empty</strong> subarray from <code>nums</code> that has the <strong>maximum</strong> possible <strong>bitwise AND</strong>.</p>

<ul>
	<li>In other words, let <code>k</code> be the maximum value of the bitwise AND of <strong>any</strong> subarray of <code>nums</code>. Then, only subarrays with a bitwise AND equal to <code>k</code> should be considered.</li>
</ul>

<p>Return <em>the length of the <strong>longest</strong> such subarray</em>.</p>

<p>The bitwise AND of an array is the bitwise AND of all the numbers in it.</p>

<p>A <strong>subarray</strong> is a contiguous sequence of elements within an array.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,2,3,3,2,2]
<strong>Output:</strong> 2
<strong>Explanation:</strong>
The maximum possible bitwise AND of a subarray is 3.
The longest subarray with that value is [3,3], so we return 2.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,2,3,4]
<strong>Output:</strong> 1
<strong>Explanation:</strong>
The maximum possible bitwise AND of a subarray is 4.
The longest subarray with that value is [4], so we return 1.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= nums[i] &lt;= 10<sup>6</sup></code></li>
</ul>

class Solution:
    def longestSubarray(self, nums: List[int]) -> int:
        """
        Simply find the max biwise and, and then find all occurrences of it, we can count this as we search the array initially
        """
        max_num = max(nums)

        max_length = 0
        curr_length = 0
        for num in nums:
            if num == max_num:
                curr_length += 1
            
            else:
                curr_length = 0
        
            max_length = max(max_length, curr_length)
        
        return max_length

        # max_length = 0
        # max_and = 0

        # curr_length = 0
        # curr_and = 1
        # for num in nums:
        #     cur_and = num & curr_and
        #     curr_length += 1
            
        #     if curr_and >= max_and:
        #         max_and = curr_and
        #     if curr_length > max_length:
        #         max_length = curr_length
            
        #     if curr_and < max_and:
        #         curr_length = 0
        #         curr_and = 1
        
        # return max_length
        # max_num = max(nums)
        # counts = [0]*(max_num+1)
        # max_and = 0
        # max_power = 0
        # max_and_nums = []

        # def count_bits(num):
        #     power = 0
        #     while num:
        #         num = num >> 1
        #         power += 1
            
        #     return power

        # #Find the greatest number of ands, and return num with greatest ands and highest count
        # for num in nums:
        #     power = count_bits(num)
        #     max_power = max(power, max_power)

        #     #print(num, max_power, num & ((2**max_power)-1))
        #     ands = num & ((2**max_power)-1)
        #     #print("Ands: ", ands, max_and)
        #     if ands > max_and:
        #         max_and_nums = [num]
        #         max_and = ands
        #     elif ands == max_and:
        #         max_and_nums.append(num)
            
        #     counts[num] += 1

        # #print(counts, max_and_nums)
        # return max([counts[i] for i in max_and_nums])

            

        
        
29700