< Ace Coding /> 🚀: post #380 — TG.ME

"""
You are given a string s consisting only of the letters 'a' and 'b', and an integer k.
What is the minimum number of characters you need to change to obtain a substring of length ≥ k where all characters are the same?

Example 1:
s = “aabaabaa”, k = 3
Output: 1
Explanation: s can be transformed to “aaaaabaa”

Example 2:
s = “bbabbaba”, k = 8
Output: 3
Explanation: s can be transformed to “bbbbbbbb”

Constraints:
1 <= s.length <= 10^5
1 <= k <= s.length

aaab, k = 4
aaaa
abs(3 - 1) = 2
"""
👍3
December 21, 2024 387 8