Class Solution
java.lang.Object
g2001_2100.s2086_minimum_number_of_buckets_required_to_collect_rainwater_from_houses.Solution
2086 - Minimum Number of Buckets Required to Collect Rainwater from Houses.<p>Medium</p>
<p>You are given a <strong>0-index****ed</strong> string <code>street</code>. Each character in <code>street</code> is either <code>'H'</code> representing a house or <code>'.'</code> representing an empty space.</p>
<p>You can place buckets on the <strong>empty spaces</strong> to collect rainwater that falls from the adjacent houses. The rainwater from a house at index <code>i</code> is collected if a bucket is placed at index <code>i - 1</code> <strong>and/or</strong> index <code>i + 1</code>. A single bucket, if placed adjacent to two houses, can collect the rainwater from <strong>both</strong> houses.</p>
<p>Return <em>the <strong>minimum</strong> number of buckets needed so that for <strong>every</strong> house, there is <strong>at least</strong> one bucket collecting rainwater from it, or</em> <code>-1</code> <em>if it is impossible.</em></p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> street = “H..H”</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong></p>
<p>We can put buckets at index 1 and index 2.</p>
<p>“H..H” -> “HBBH” (‘B’ denotes where a bucket is placed).</p>
<p>The house at index 0 has a bucket to its right, and the house at index 3 has a bucket to its left.</p>
<p>Thus, for every house, there is at least one bucket collecting rainwater from it.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> street = “.H.H.”</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong></p>
<p>We can put a bucket at index 2.</p>
<p>“.H.H.” -> “.HBH.” (‘B’ denotes where a bucket is placed).</p>
<p>The house at index 1 has a bucket to its right, and the house at index 3 has a bucket to its left.</p>
<p>Thus, for every house, there is at least one bucket collecting rainwater from it.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> street = “.HHH.”</p>
<p><strong>Output:</strong> -1</p>
<p><strong>Explanation:</strong></p>
<p>There is no empty space to place a bucket to collect the rainwater from the house at index 2.</p>
<p>Thus, it is impossible to collect the rainwater from all the houses.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= street.length <= 10<sup>5</sup></code></li>
<li><code>street[i]</code> is either<code>'H'</code> or <code>'.'</code>.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minimumBuckets
-