Skip to content

Commit 153b451

Browse files
committed
Create README - LeetHub
1 parent d4b8ac9 commit 153b451

File tree

1 file changed

+53
-0
lines changed
  • 2618-maximize-the-minimum-powered-city

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<h2><a href="https://leetcode.com/problems/maximize-the-minimum-powered-city">2618. Maximize the Minimum Powered City</a></h2><h3>Hard</h3><hr><p>You are given a <strong>0-indexed</strong> integer array <code>stations</code> of length <code>n</code>, where <code>stations[i]</code> represents the number of power stations in the <code>i<sup>th</sup></code> city.</p>
2+
3+
<p>Each power station can provide power to every city in a fixed <strong>range</strong>. In other words, if the range is denoted by <code>r</code>, then a power station at city <code>i</code> can provide power to all cities <code>j</code> such that <code>|i - j| &lt;= r</code> and <code>0 &lt;= i, j &lt;= n - 1</code>.</p>
4+
5+
<ul>
6+
<li>Note that <code>|x|</code> denotes <strong>absolute</strong> value. For example, <code>|7 - 5| = 2</code> and <code>|3 - 10| = 7</code>.</li>
7+
</ul>
8+
9+
<p>The <strong>power</strong> of a city is the total number of power stations it is being provided power from.</p>
10+
11+
<p>The government has sanctioned building <code>k</code> more power stations, each of which can be built in any city, and have the same range as the pre-existing ones.</p>
12+
13+
<p>Given the two integers <code>r</code> and <code>k</code>, return <em>the <strong>maximum possible minimum power</strong> of a city, if the additional power stations are built optimally.</em></p>
14+
15+
<p><strong>Note</strong> that you can build the <code>k</code> power stations in multiple cities.</p>
16+
17+
<p>&nbsp;</p>
18+
<p><strong class="example">Example 1:</strong></p>
19+
20+
<pre>
21+
<strong>Input:</strong> stations = [1,2,4,5,0], r = 1, k = 2
22+
<strong>Output:</strong> 5
23+
<strong>Explanation:</strong>
24+
One of the optimal ways is to install both the power stations at city 1.
25+
So stations will become [1,4,4,5,0].
26+
- City 0 is provided by 1 + 4 = 5 power stations.
27+
- City 1 is provided by 1 + 4 + 4 = 9 power stations.
28+
- City 2 is provided by 4 + 4 + 5 = 13 power stations.
29+
- City 3 is provided by 5 + 4 = 9 power stations.
30+
- City 4 is provided by 5 + 0 = 5 power stations.
31+
So the minimum power of a city is 5.
32+
Since it is not possible to obtain a larger power, we return 5.
33+
</pre>
34+
35+
<p><strong class="example">Example 2:</strong></p>
36+
37+
<pre>
38+
<strong>Input:</strong> stations = [4,4,4,4], r = 0, k = 3
39+
<strong>Output:</strong> 4
40+
<strong>Explanation:</strong>
41+
It can be proved that we cannot make the minimum power of a city greater than 4.
42+
</pre>
43+
44+
<p>&nbsp;</p>
45+
<p><strong>Constraints:</strong></p>
46+
47+
<ul>
48+
<li><code>n == stations.length</code></li>
49+
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
50+
<li><code>0 &lt;= stations[i] &lt;= 10<sup>5</sup></code></li>
51+
<li><code>0 &lt;= r&nbsp;&lt;= n - 1</code></li>
52+
<li><code>0 &lt;= k&nbsp;&lt;= 10<sup>9</sup></code></li>
53+
</ul>

0 commit comments

Comments
 (0)