Minimum White Tiles After Covering With Carpets

You are given a 0-indexed binary string floor, which represents the colors of tiles on a floor:

  • floor[i] = '0' denotes that the i^th tile of the floor is colored black.
  • floor[i] = '1' denotes that the i^th tile of the floor is colored white.

You are also given numCarpets and carpetLen. You have numCarpets black carpets, each of length carpetLen tiles. Cover the tiles with the given carpets such that the number of white tiles still visible is minimum. Carpets may overlap one another.

Return the minimum number of white tiles still visible.

Example 1
Inputfloor = "10110101", numCarpets = 2, carpetLen = 2
Output2
One way of covering the tiles with the carpets leaves only 2 white tiles visible, and no covering can leave fewer than 2 visible white tiles.
Example 2
Inputfloor = "11111", numCarpets = 2, carpetLen = 3
Output0
The carpets can overlap, allowing all white tiles to be covered so that no white tiles remain visible.

Constraints

  • 1 <= carpetLen <= floor.length <= 1000
  • floor[i] is either '0' or '1'.
  • 1 <= numCarpets <= 1000

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate