java.lang.Object
g2201_2300.s2271_maximum_white_tiles_covered_by_a_carpet.Solution

public class Solution extends Object
2271 - Maximum White Tiles Covered by a Carpet.<p>Medium</p> <p>You are given a 2D integer array <code>tiles</code> where <code>tiles[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represents that every tile <code>j</code> in the range <code>l<sub>i</sub> <= j <= r<sub>i</sub></code> is colored white.</p> <p>You are also given an integer <code>carpetLen</code>, the length of a single carpet that can be placed <strong>anywhere</strong>.</p> <p>Return <em>the <strong>maximum</strong> number of white tiles that can be covered by the carpet</em>.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2022/03/25/example1drawio3.png" alt="" /></p> <p><strong>Input:</strong> tiles = [[1,5],[10,11],[12,18],[20,25],[30,32]], carpetLen = 10</p> <p><strong>Output:</strong> 9</p> <p><strong>Explanation:</strong> Place the carpet starting on tile 10.</p> <p>It covers 9 white tiles, so we return 9.</p> <p>Note that there may be other places where the carpet covers 9 white tiles.</p> <p>It can be shown that the carpet cannot cover more than 9 white tiles.</p> <p><strong>Example 2:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2022/03/24/example2drawio.png" alt="" /></p> <p><strong>Input:</strong> tiles = [[10,11],[1,1]], carpetLen = 2</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> Place the carpet starting on tile 10.</p> <p>It covers 2 white tiles, so we return 2.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= tiles.length <= 5 * 10<sup>4</sup></code></li> <li><code>tiles[i].length == 2</code></li> <li><code>1 <= l<sub>i</sub> <= r<sub>i</sub> <= 10<sup>9</sup></code></li> <li><code>1 <= carpetLen <= 10<sup>9</sup></code></li> <li>The <code>tiles</code> are <strong>non-overlapping</strong>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maximumWhiteTiles

      public int maximumWhiteTiles(int[][] tiles, int carpetLength)