Skip to content

Practice Longest Nice Subarray

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2401
LeetCode Problem

Longest Nice Subarray

Problem Statement

You are given an array nums consisting of positive integers. We call a subarray of nums nice if the bitwise AND of every pair of elements that are in different positions in the subarray is equal to 0. Return the length of the longest nice subarray. A subarray is a contiguous part of an array. Note that subarrays of length 1 are always considered nice.

Source: Longest Nice Subarray on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,3,8,48,10]
Output
3

# Example 2

Input
nums = [3,1,5,11,13]
Output
1

Constraints

1 <= nums.length <= 10^5
1 <= nums[i] <= 10^9

Related LeetCode Problems

Practice more problems similar to Longest Nice Subarray.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.