java.lang.Object
g2201_2300.s2209_minimum_white_tiles_after_covering_with_carpets.Solution

public class Solution extends Object
2209 - Minimum White Tiles After Covering With Carpets.<p>Hard</p> <p>You are given a <strong>0-indexed binary</strong> string <code>floor</code>, which represents the colors of tiles on a floor:</p> <ul> <li><code>floor[i] = '0'</code> denotes that the <code>i<sup>th</sup></code> tile of the floor is colored <strong>black</strong>.</li> <li>On the other hand, <code>floor[i] = '1'</code> denotes that the <code>i<sup>th</sup></code> tile of the floor is colored <strong>white</strong>.</li> </ul> <p>You are also given <code>numCarpets</code> and <code>carpetLen</code>. You have <code>numCarpets</code> <strong>black</strong> carpets, each of length <code>carpetLen</code> tiles. Cover the tiles with the given carpets such that the number of <strong>white</strong> tiles still visible is <strong>minimum</strong>. Carpets may overlap one another.</p> <p>Return <em>the <strong>minimum</strong> number of white tiles still visible.</em></p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2022/02/10/ex1-1.png" alt="" /></p> <p><strong>Input:</strong> floor = &ldquo;10110101&rdquo;, numCarpets = 2, carpetLen = 2</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong></p> <p>The figure above shows one way of covering the tiles with the carpets such that only 2 white tiles are visible.</p> <p>No other way of covering the tiles with the carpets can leave less than 2 white tiles visible.</p> <p><strong>Example 2:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2022/02/10/ex2.png" alt="" /></p> <p><strong>Input:</strong> floor = &ldquo;11111&rdquo;, numCarpets = 2, carpetLen = 3</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong></p> <p>The figure above shows one way of covering the tiles with the carpets such that no white tiles are visible.</p> <p>Note that the carpets are able to overlap one another.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= carpetLen <= floor.length <= 1000</code></li> <li><code>floor[i]</code> is either <code>'0'</code> or <code>'1'</code>.</li> <li><code>1 <= numCarpets <= 1000</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • minimumWhiteTiles

      public int minimumWhiteTiles(String floor, int numCarpets, int carpetLen)