Skip to content
We areTOP 1%

Bitwise ORs of Subarrays

MediumLeetCodeBit Manipulation
Solve on LeetCode(opens in a new tab)
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews
Approach hintTry it first, then reveal

OR values of subarrays ending at a fixed index only gain bits as the start moves left, so there are at most about 30 distinct ones. Carry that small set along the scan and add its members to a global set.

More in Bit Manipulation

Bit Manipulation questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Single Number IILeetCodeMedium Solve Single Number II on LeetCode (opens in a new tab)
2Single Number IIILeetCodeMedium Solve Single Number III on LeetCode (opens in a new tab)
3Bitwise AND of Numbers RangeLeetCodeMedium Solve Bitwise AND of Numbers Range on LeetCode (opens in a new tab)
4Total Hamming DistanceLeetCodeMedium Solve Total Hamming Distance on LeetCode (opens in a new tab)
5Find the Longest Substring Containing Vowels in Even CountsLeetCodeMedium Solve Find the Longest Substring Containing Vowels in Even Counts on LeetCode (opens in a new tab)
6AGAGA XOOORRRCodeforcesMedium 1500Solve AGAGA XOOORRR on Codeforces (opens in a new tab)
7Data Structures FanCodeforcesMedium 1500Solve Data Structures Fan on Codeforces (opens in a new tab)
8Boboniu and Bit OperationsCodeforcesMedium 1600Solve Boboniu and Bit Operations on Codeforces (opens in a new tab)
9Bitwise ORs of SubarraysLeetCodeMedium Solve Bitwise ORs of Subarrays on LeetCode (opens in a new tab)
10AND, OR and square sumCodeforcesMedium 1700Solve AND, OR and square sum on Codeforces (opens in a new tab)
11Little Girl and Maximum XORCodeforcesMedium 1700Solve Little Girl and Maximum XOR on Codeforces (opens in a new tab)
12BitsCodeforcesMedium 1700Solve Bits on Codeforces (opens in a new tab)

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account