I have participated in October Long Challege and submitted my solution for ANDSUBAR problem. I have tried the logic which I suited to be right. Help me figure it out!

For any given number N, the bitwise AND of all odd numbers in a set (1,2,3,…,N) is 1 that is positive. So the solution for maximum elements in an array whose bitwise AND is positive is N/2 for even number and (N+1)/2 in case of odd number as input. Please provide your suggestion.

Considering this solution of yours, it fails for the following test case.

**Input**

```
1
10
```

**Expected Output**

```
4
```

**Your Output**

```
5
```

2 Likes

In the question Longest And Subarray was asked.

Subarray is continuos part of an array.

Now,Lets take an example 10.

According to your logic the answer is 5 {1,3,5,7,9} but these number are not continuos as they should be in a subarray.So , correct answer for it would be 4 {4,5,6,7}.

1 Like

Got it. Thanks.