#K50362. Longest Contiguous Subarray with Bitwise AND Constraint

    ID: 28848 Type: Default 1000ms 256MiB

Longest Contiguous Subarray with Bitwise AND Constraint

Longest Contiguous Subarray with Bitwise AND Constraint

You are given an array of non-negative integers and an integer \(k\). Your task is to determine the length of the longest contiguous subarray such that the bitwise AND of all its elements is greater than or equal to \(k\). If no such subarray exists, output 0.

The bitwise AND operation is performed on the binary representations of the numbers. This problem tests your knowledge of bitwise operations and efficient subarray processing techniques.

inputFormat

The input is given via standard input (stdin) and consists of two lines. The first line contains two integers (n) and (k), where (n) is the number of array elements and (k) is the threshold value for the bitwise AND. The second line contains (n) space-separated integers representing the array elements.

outputFormat

Output a single integer to standard output (stdout) indicating the length of the longest contiguous subarray whose bitwise AND of all elements is at least (k). If no such subarray exists, output 0.## sample

5 3
4 3 2 6 7
2