Leetcode 898. Bitwise ORs of Subarrays
Count how many distinct integers appear as the bitwise OR of any non-empty contiguous subarray of arr. Key insight: bitwise OR only accumulates bits so the number of distinct ORs ending at each position is bounded (≈bit-width of numbers), allowing an efficient iterative set-based accumulation for n up to 5·10^4 and values ≤ 10^9.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Early September, 2026
Compromised Subarrays You're given an integer array codes of length n. A subarray (a contiguous, non-empty segment) is "compromised" if the bitwise OR of all its elements equals some value that appears anywhere in codes. The matching value does not have to be inside the subarray itself. Return the number of compromised subarrays. Note: every subarray of length 1 is compromised, since its OR is its own element. Example 1: Input: codes = [5, 1, 4] Output: 6 Explanation: [5]=5 ✓ [1]=1 ✓ [4]=4 ✓ [5,1]=5 ✓ [1,4]=5 ✓ (matches the 5 outside the subarray) [5,1,4]=5 ✓ Example 2: Input: codes = [1, 2, 4] Output: 3 Explanation: Only the three single-element subarrays. [1,2]=3, [2,4]=6 and [1,2,4]=7 don't appear in codes. Constraints: 1 <= n <= 10^5 0 <= codes[i] <= 10^9 Function signature: long countCompromised(int[] codes)
Late January, 2026
Same as the leetcode question, minus some flavor text
Hello Interview Premium
Your account is free and you can post anonymously if you choose.