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.
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.
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.
Accepted:
Submission: