Imagine you're an urban planner tasked with optimizing the power grid distribution across n cities arranged in a line. Each city currently has some number of power stations, given in the array stations[i].
Here's the key: each power station has a fixed range r, meaning a station in city i can provide power to all cities j where |i - j| <= r. The power of a city is the total number of stations that can reach it.
The government has approved funding for k additional power stations that you can place strategically in any cities. Your goal is to maximize the minimum power across all cities - essentially, you want to ensure even the least-powered city has as much power as possible.
Example: If stations = [1,2,4,5,0], r = 1, and k = 2, you need to determine the optimal placement of 2 new stations to maximize the minimum power any city receives.
Input & Output
Visualization
Time & Space Complexity
Binary search runs log(sum+k) iterations, each validation takes O(n) time with sliding window
Space for storing current power configuration and additional stations placed
Constraints
- n == stations.length
- 1 โค n โค 105
- 0 โค stations[i] โค 105
- 0 โค r โค n - 1
- 0 โค k โค 109
- Large k values require efficient O(n log n) solution