#2401
Longest Nice Subarray
specialist · 635 · lc medium +30 · verified · 64.8% accepted · 2,083 likes · top 68%
Description
Given an array nums of positive integers, a subarray is nice if the bitwise AND of every pair of elements at different positions within it is 0.
Return the length of the longest nice subarray. (A subarray is a contiguous portion of the array.)
Example 1:
Input: nums = [1,3,8,48,10]
Output: 3
Explanation: The longest nice subarray is [3,8,48]. This subarray satisfies the conditions:
- 3 AND 8 = 0.
- 3 AND 48 = 0.
- 8 AND 48 = 0.
It can be proven that no longer nice subarray can be obtained, so we return 3.
Example 2:
Input: nums = [3,1,5,11,13]
Output: 1
Explanation: The length of the longest nice subarray is 1. Any subarray of length 1 can be chosen.
Code
1
2
3