Trains the technique from
LeetCode 2528Maximize the Minimum Powered CityThis 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 single road has n numbered stops. stations[i] is how many relay masts stand at stop i. A mast standing at stop j puts signal on every stop i with |i - j| <= r, so the signal at stop i is the number of masts standing at stops within r of it, counting every mast at every such stop.
You may erect k further masts. Each one has to stand at one of the n stops, several new masts may share a stop, and they may share a stop with existing masts. You do not have to erect all k.
Return the largest value the weakest stop's signal can be raised to, that is the largest possible value of the smallest signal over all n stops.
Example 1
The starting signals are 3, 7, 11, 9 and 5. Erecting both new masts at stop 1 gives the stop counts [1, 4, 4, 5, 0] and signals 5, 9, 13, 9 and 5, so the weakest stop reads 5.
Example 2
A single mast at stop 1 reaches stops 0, 1 and 2, so every stop reads 1.
Example 3
With a reach of 0 each stop only sees its own masts, and no new mast may be erected, so the weakest signal stays at 4.
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 max_power(stations: list[int], r: int, k: int) -> int:public long maxPower(int[] stations, int r, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.