Ctrl K

Signal in the Remotest Village

Hard
There are n villages along a road, numbered 0 to n - 1, and village i already has towers[i] cell towers. Each tower covers the villages within distance reach: a tower in village i reaches village j if |i - j| ≤ reach. The signal of a village is the number of towers that cover it. The budget allows budget more towers with the same range; they can go into any villages, several into one if you like. Return the largest possible value of the weakest signal among all villages once the new towers are in place.
Example 1
towers=[0, 3, 0, 0, 1], reach=1, budget=2 → 3

Without new towers the signals are [3, 3, 3, 1, 1]. Two new towers in village 3 give [3, 3, 5, 3, 3], a minimum of 3, and nothing does better.

Example 2
towers=[2, 0, 5], reach=0, budget=4 → 3

Each tower covers only its own village. Three new towers go to village 1 and one to village 0: signals [3, 3, 5].

Example 3
towers=[1, 1, 1, 1, 1, 1], reach=2, budget=0 → 3
Constraints
  • 1 ≤ n = len(towers) ≤ 10⁵
  • 0 ≤ towers[i] ≤ 10⁵
  • 0 ≤ reach ≤ n - 1
  • 0 ≤ budget ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsShortest Stretch Reaching a Total HardLongest Affordable Run of Machines HardEven Out With Increments MediumRug Over Painted Stretches MediumRichest Row of Houses Medium
loading Python…
Input
towers=[0, 3, 0, 0, 1], reach=1, budget=2
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 121 tests on the server, hidden ones included.