2209. Minimum White Tiles After Covering With Carpets Hard

@problem@discussion
#String#Dynamic Programming#Prefix Sum



1/**
2 * [2209] Minimum White Tiles After Covering With Carpets
3 *
4 * You are given a 0-indexed binary string floor, which represents the colors of tiles on a floor:
5 * 
6 * 	floor[i] = '0' denotes that the i^th tile of the floor is colored black.
7 * 	On the other hand, floor[i] = '1' denotes that the i^th tile of the floor is colored white.
8 * 
9 * 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.
10 * Return the minimum number of white tiles still visible.
11 *  
12 * Example 1:
13 * <img alt="" src="https://assets.leetcode.com/uploads/2022/02/10/ex1-1.png" style="width: 400px; height: 73px;" />
14 * Input: floor = "10110101", numCarpets = 2, carpetLen = 2
15 * Output: 2
16 * Explanation: 
17 * The figure above shows one way of covering the tiles with the carpets such that only 2 white tiles are visible.
18 * No other way of covering the tiles with the carpets can leave less than 2 white tiles visible.
19 * 
20 * Example 2:
21 * <img alt="" src="https://assets.leetcode.com/uploads/2022/02/10/ex2.png" style="width: 353px; height: 123px;" />
22 * Input: floor = "11111", numCarpets = 2, carpetLen = 3
23 * Output: 0
24 * Explanation: 
25 * The figure above shows one way of covering the tiles with the carpets such that no white tiles are visible.
26 * Note that the carpets are able to overlap one another.
27 * 
28 *  
29 * Constraints:
30 * 
31 * 	1 <= carpetLen <= floor.length <= 1000
32 * 	floor[i] is either '0' or '1'.
33 * 	1 <= numCarpets <= 1000
34 * 
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/minimum-white-tiles-after-covering-with-carpets/
39// discuss: https://leetcode.com/problems/minimum-white-tiles-after-covering-with-carpets/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44    pub fn minimum_white_tiles(floor: String, num_carpets: i32, carpet_len: i32) -> i32 {
45        0
46    }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53    use super::*;
54
55    #[test]
56    fn test_2209() {
57    }
58}
59


Back
© 2025 bowen.ge All Rights Reserved.