#C4540. Longest Subarray with Positive Bitwise AND
Longest Subarray with Positive Bitwise AND
Longest Subarray with Positive Bitwise AND
You are given an array of n integers. Your task is to find the length of the longest contiguous subarray such that the bitwise AND of all its elements is greater than zero. In other words, if the bitwise AND of a subarray is denoted by \( A \), then we require \( A > 0 \).
Note that the subarray must be contiguous, and the bitwise AND operation is performed on all the elements within that subarray. If no such subarray exists, the answer is 0.
Example:
Input: n = 3, arr = [4, 2, 8] Output: 1</p>Explanation: The longest subarray with a positive bitwise AND is either [4] or [8]. The subarray [4,2] results in 0 because 4 & 2 = 0.
inputFormat
The input is given via stdin and is formatted as follows:
- The first line contains an integer n representing the number of elements in the array.
- The second line contains n space-separated integers, representing the elements of the array.
outputFormat
Output a single integer to stdout which is the length of the longest contiguous subarray such that the bitwise AND of all its elements is greater than zero.
## sample3
4 2 8
1
</p>