2419. Longest Subarray With Maximum Bitwise AND - Explanation

Problem Link

Description

Compute the bitwise AND of each nonempty contiguous subarray of nums. Among the subarrays that attain the largest possible AND value, return the greatest length.

Example 1:

Input: nums = [1]

Output: 1

Explanation: The only subarray is [1], whose bitwise AND is 1 and whose length is 1.

Example 2:

Input: nums = [1,1]

Output: 2

Explanation: The greatest possible AND is 1. The entire array [1,1] attains it, giving length 2.

Example 3:

Input: nums = [1,2]

Output: 1

Explanation: The greatest possible AND is 2, attained by the one-entry subarray [2]. The whole array has AND 0.

Constraints:

  • 1 <= nums.length <= 100000
  • 1 <= nums[i] <= 1000000


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.