Imagine you're an interior designer with a special carpet that you want to place optimally to cover as many white tiles as possible on a floor.
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. Think of this as continuous segments of white tiles on a number line.
You also have a carpet of fixed length carpetLen that can be placed anywhere on this number line.
Goal: Find the optimal position to place your carpet so that it covers the maximum number of white tiles.
Example: If you have white tile segments [[1,5], [10,11], [12,18]] and a carpet of length 4, you need to find where to place this carpet to cover the most white tiles possible.
Input & Output
Constraints
- 1 โค tiles.length โค 5 ร 104
- tiles[i].length == 2
- 1 โค li โค ri โค 109
- 1 โค carpetLen โค 109
- No two tiles overlap (tiles represent disjoint segments)