Skip to content

Practice Maximum White Tiles Covered by a Carpet

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2271
LeetCode Problem

Maximum White Tiles Covered by a Carpet

Problem Statement

You are given a 2D integer array tiles where tiles[i] = [li, ri] represents that every tile j in the range li <= j <= ri is colored white. You are also given an integer carpetLen, the length of a single carpet that can be placed anywhere. Return the maximum number of white tiles that can be covered by the carpet.

Source: Maximum White Tiles Covered by a Carpet on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
tiles = [[1,5],[10,11],[12,18],[20,25],[30,32]], carpetLen = 10
Output
9

# Example 2

Input
tiles = [[10,11],[1,1]], carpetLen = 2
Output
2

Constraints

1 <= tiles.length <= 5 * 10^4
tiles[i].length == 2
1 <= li <= ri <= 10^9
1 <= carpetLen <= 10^9
The tiles are non-overlapping.

Related LeetCode Problems

Practice more problems similar to Maximum White Tiles Covered by a Carpet.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.