Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Maximum White Tiles Covered by a Carpet

XPChallenge Points: 20
levelLevel: Medium

You are given an array tiles, where each element [l, r] means all tiles from position l to r are white.

You are also given an integer carpetLen, representing the length of one carpet. You can place this carpet anywhere on the number line.

Your task is to find the maximum number of white tiles the carpet can cover when placed in the best possible position.

Example 1:

Input: tiles = [[2,6],[15,17],[18,22],[5,9]], carpetLen = 7

Output: 9

Explanation:

Placing the carpet starting at tile 5 covers tiles [5,11], and fully covers tiles [5,9] plus part of [2,6]. Maximum total covered = 7.

Example 2:

Input: tiles = [[4,4],[7,10],[12,14]], carpetLen = 3

Output: 3

Explanation:

Placing the carpet from 7 to 10 gives full coverage of 3 tiles.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result