Trains the technique from
LeetCode 898Bitwise ORs of SubarraysThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A list of channel masks reads masks, each a whole number whose bits say which channels it claims.
Merging a run of neighbouring masks claims every channel any of them claims, so the merged mask has a bit set exactly where at least one mask of the run has it set.
Return how many different merged masks arise over all the runs of one or more neighbouring masks.
Example 1
The single masks give 1, 2 and 3. Merging 1 with 2 gives 3, merging 2 with 3 gives 3, and merging all three gives 3, so only 1, 2 and 3 ever arise.
Example 2
Every mask claims the same channels, so every run merges to the same mask.
Example 3
No mask claims any channel, so every run merges to nothing.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def subarray_bitwise_o_rs(masks: list[int]) -> int:public int subarrayBitwiseORs(int[] masks)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.