Skip to content

2411. Smallest Subarrays With Maximum Bitwise OR #1984

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to find, for each starting index i in the given array, the smallest subarray starting at i that achieves the maximum possible bitwise OR for any subarray starting at i. The bitwise OR of a subarray is the bitwise OR of all elements in that subarray. The challenge is to efficiently compute this for each index in the array.

Approach

  1. Problem Analysis: The key observation is that the maximum bitwise OR for any subarray starting at index i is the bitwise OR of the entire subarray from i to the end of the array. This is because the bitwise OR operation is monotonic; adding more elements can only set more bits, never unset them. Therefore, the maximum OR value for subarrays starting at i

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Jul 29, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Jul 29, 2025
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants