Loading problem...
You are a floor designer working with a sequence of decorative tiles arranged in a row. The tile arrangement is represented as a 0-indexed string tiles of length n, where each character indicates the current color of the tile at that position:
'D' represents a dark-colored tile'L' represents a light-colored tileYour goal is to create a visually striking design by having at least k consecutive dark-colored tiles somewhere in the arrangement. To achieve this, you can repaint any light-colored tile to transform it into a dark-colored tile. Each repaint operation changes exactly one 'L' tile to a 'D' tile.
Your Task: Determine the minimum number of repaint operations required to ensure that there exists at least one contiguous segment of exactly k consecutive dark-colored tiles in the final arrangement.
This is a classic application of the sliding window technique, where you need to find the optimal window of size k that requires the fewest transformations to become entirely dark-colored.
tiles = "LDDLLDDDLD"
k = 73We need to find 7 consecutive dark tiles. Looking at the tiles from index 0 to 6 ("LDDLLDD"), we count 3 light tiles that need repainting. After repainting positions 0, 3, and 4, the arrangement becomes "DDDDDDDLD", which contains the required 7 consecutive dark tiles. This is the minimum number of repaints needed.
tiles = "LDLDDDL"
k = 20Looking at the current arrangement, we can find positions 3-4 ("DD") which already contains 2 consecutive dark tiles. Since the requirement is already satisfied, no repaints are needed.
tiles = "DLDDD"
k = 30The substring starting at index 2 ("DDD") already contains exactly 3 consecutive dark tiles, so no repainting operations are required.
Constraints