All problems
0490MediumArrayGreedyBit ManipulationPrefix Sum

Boosting the Channel Panel

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2680Maximum OR

This 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 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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def best_panel_reading(codes: list[int], boosts: int) -> int:
Java
public long bestPanelReading(int[] codes, int boosts)
September 7
Apply