Notice Period

Uniform Fence Stretch

medium

A long fence is painted board by board; boards is a string where each character is a board's color code. You have enough paint to recoat at most k boards.

Return the length of the longest contiguous stretch you can make entirely one color after at most k recoats.

Example 1
in boards = "ABAB", k = 2
out 4
Repaint both A's (or both B's) — the whole fence matches.
Example 2
in boards = "AABABBA", k = 1
out 4
Repaint the middle A in "ABBA" to get "BBBB" within "AABBBBA".
Constraints
  • · 1 <= len(boards) <= 2000
  • · boards consists of uppercase English letters
  • · 0 <= k <= len(boards)
similar problem on LeetCode ↗
solution.pyloading python…
test results
Hit ▶ Run to test your code against the visible cases.