Trains the technique from
LeetCode 2044Count Number of Maximum Bitwise-OR SubsetsThis 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 rack holds relays, and relays[i] is a whole number saying which lines relay i closes: the lines are the bits of that number.
Picking a group of one or more relays closes every line that any relay in the group closes, so the group's reach is the bitwise OR of the numbers in it.
Let the widest reach be the largest reach any group can manage. Return how many groups reach it. Two groups count apart when they use different relays, even if their reaches match.
Example 1
Both relays close the same single line, so the widest reach is that line and all three non-empty groups manage it.
Example 2
Together the relays close three lines. Only one relay closes the third of them, so it belongs to every group that reaches the widest, and the other three relays supply the remaining two lines in five ways.
Example 3
Each relay closes a line no other relay touches, so only the group holding all four reaches the widest.
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 count_max_or_subsets(relays: list[int]) -> int:public int countMaxOrSubsets(int[] relays)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.