Skip to content

Commit bc87754

Browse files
committed
Mar 08
1 parent b24a9c6 commit bc87754

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution:
2+
def minimumRecolors(self, blocks: str, k: int) -> int:
3+
black, max_black = 0, 0
4+
for idx in range(len(blocks)):
5+
black += blocks[idx] == 'B'
6+
if idx >= k:
7+
black -= blocks[idx-k] == 'B'
8+
max_black = max(max_black, black)
9+
return k - max_black
10+
11+
12+
def main():
13+
blocks = 'WBBWWBBWBW'
14+
k = 7
15+
assert Solution().minimumRecolors(blocks, k) == 3
16+
17+
blocks = 'WBWBBBW'
18+
k = 2
19+
assert Solution().minimumRecolors(blocks, k) == 0
20+
21+
22+
if __name__ == '__main__':
23+
main()

2025-03-March-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
| March 05 | [2579. Count Total Number of Colored Cells](https://leetcode.com/problems/count-total-number-of-colored-cells/) | Medium | Solved |
1212
| March 06 | [2965. Find Missing and Repeated Values](https://leetcode.com/problems/find-missing-and-repeated-values/) | Easy | Solved |
1313
| March 07 | [2523. Closest Prime Numbers in Range](https://leetcode.com/problems/closest-prime-numbers-in-range/) | Medium | Unsolved |
14-
| March 08 | []() | | |
14+
| March 08 | [2379. Minimum Recolors to Get K Consecutive Black Blocks](https://leetcode.com/problems/minimum-recolors-to-get-k-consecutive-black-blocks/) | Easy | Solved |
1515
| March 09 | []() | | |
1616
| March 10 | []() | | |
1717
| March 11 | []() | | |
@@ -40,6 +40,6 @@
4040
## Summary
4141
| Level | Problems | Solved | Unsolved |
4242
| --- | --- | --- | --- |
43-
| Easy | 3 | 3 | 0 |
43+
| Easy | 4 | 4 | 0 |
4444
| Medium | 4 | 3 | 1 |
4545
| Hard | 0 | 0 | 0 |

0 commit comments

Comments
 (0)