Hyoseo Lee
Home About Projects Blog Thinking
leetcode

2379. Minimum Recolors to Get K Consecutive Black Blocks

Topic Easy
Area Algorithms

Problem

View on LeetCode →

Difficulty: Easy
Tags: Mid Level, String, Sliding Window, Biweekly Contest 85

Intuition

This one was also too easy. this was basically the same problem with 2269. but with different words.

All i need to do is counting White blocks in consecutive k-element substring.

Approach

go through all k-substring of blocks, and find the minimum number of W block in that sub-string.

Solution

class Solution:
    def minimumRecolors(self, blocks: str, k: int) -> int:
        ans = k
        for i in range(len(blocks)-k+1):
            tmp = blocks[i:i+k].count("W")
            if tmp < ans:
                ans = tmp
        return ans

Complexity

Thoughts

This was too easy. maybe it’s time to level up to Medium level