Skip to content

Practice Smallest Subarrays With Maximum Bitwise OR

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

Medium#2411
LeetCode Problem

Smallest Subarrays With Maximum Bitwise OR

Problem Statement

You are given a 0-indexed array nums of length n, consisting of non-negative integers. For each index i from 0 to n - 1, you must determine the size of the minimum sized non-empty subarray of nums starting at i (inclusive) that has the maximum possible bitwise OR. The bitwise OR of an array is the bitwise OR of all the numbers in it. Return an integer array answer of size n where answer[i] is the length of the minimum sized subarray starting at i with maximum bitwise OR. A subarray is a contiguous non-empty sequence of elements within an array.

Source: Smallest Subarrays With Maximum Bitwise OR on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,0,2,1,3]
Output
[3,3,2,2,1]

# Example 2

Input
nums = [1,2]
Output
[2,1]

Constraints

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

Related LeetCode Problems

Practice more problems similar to Smallest Subarrays With Maximum Bitwise OR.

Review your practice with PhantomCodeAI

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