Class Solution
java.lang.Object
g2401_2500.s2419_longest_subarray_with_maximum_bitwise_and.Solution
2419 - Longest Subarray With Maximum Bitwise AND.<p>Medium</p>
<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><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [1,2,3,3,2,2]</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong></p>
<p>The maximum possible bitwise AND of a subarray is 3.</p>
<p>The longest subarray with that value is [3,3], so we return 2.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [1,2,3,4]</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong></p>
<p>The maximum possible bitwise AND of a subarray is 4.</p>
<p>The longest subarray with that value is [4], so we return 1.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
<li><code>1 <= nums[i] <= 10<sup>6</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
longestSubarray
public int longestSubarray(int[] nums)
-