Maximum OR
Real-world version: Boosting the Channel PanelThe statement here is our own: the same inputs, outputs and technique.
A test bench drives a wall panel from a bank of signal generators. Generator i is described by the positive integer codes[i], and the panel lights a channel whenever at least one generator carries that channel, so the panel's reading is the bitwise OR of all the generator codes.
The bench also has a tray of identical doubler modules. Fitting a doubler onto a generator replaces that generator's code with twice its current value; fitting a second doubler onto the same generator doubles it again. You may fit at most boosts doublers in total, spread across the generators however you like, including several on one generator or none at all.
Return the largest panel reading you can obtain.
Examples
Example 1
- Input
- codes = [12, 9], boosts = 1
- Output
- 30
Fitting the doubler to the generator coded 9 turns it into 18, and 18 OR 12 is 30.
Example 2
- Input
- codes = [7], boosts = 3
- Output
- 56
The lone generator absorbs all three doublers, taking 7 to 14, then 28, then 56.
Example 3
- Input
- codes = [1, 2, 4, 8], boosts = 1
- Output
- 23
Doubling the generator coded 8 gives 16, and 16 OR 4 OR 2 OR 1 is 23.
Constraints
- 1 <= codes.length <= 10^5
- 1 <= codes[i] <= 10^9
- 1 <= boosts <= 15
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def best_panel_reading(codes: list[int], boosts: int) -> int:public long bestPanelReading(int[] codes, int boosts)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 11 test cases: 11 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Longest Subsequence With Limited SumReal-world version: Parcels Within Each AllowanceEasy
- Meeting Rooms IIReal-world version: Peak Charging Bay DemandMedium
- Frequency of the Most Frequent ElementReal-world version: Plates at One ThicknessMedium
- Cinema Seat AllocationReal-world version: Study Pods in the Lecture HallMedium