Files
cpp-flashcards/org/study_deck_02/dsa/sliding-window/0424-longest-repeating-character-replacement.org
T

59 lines
1.4 KiB
Org Mode
Raw Normal View History

#+PROPERTY: STUDY_DECK_02
* TODO 0424. Longest Repeating Character Replacement :medium:
:PROPERTIES:
:NEETCODE: [[file:../../roadmap.org::*0424. Longest Repeating Character Replacement][0424. Longest Repeating Character Replacement]]
:END:
You are given a string ~s~ and an integer ~k~. You can choose any character of the string and change it to any other uppercase English character. You can perform this operation at most ~k~ times.
Return /the length of the longest substring containing the same letter you can get after performing the above operations/.
*Example 1:*
#+begin_src
Input: s = "ABAB", k = 2
Output: 4
Explanation: Replace the two 'A's with two 'B's or vice versa.
#+end_src
*Example 2:*
#+begin_src
Input: s = "AABABBA", k = 1
Output: 4
Explanation: Replace the one 'A' in the middle with 'B' and form "AABBBBA".
The substring "BBBB" has the longest repeating letters, which is 4.
There may exists other ways to achieve this answer too.
#+end_src
*Constraints:*
- ~1 <= s.length <= 10^{5}~
- ~s~ consists of only uppercase English letters.
- ~0 <= k <= s.length~
** TODO Approach
Write your approach here.
** TODO Python
#+begin_src python
class Solution:
def characterReplacement(self, s: str, k: int) -> int:
#+end_src
** TODO C++
#+begin_src cpp
class Solution {
public:
int characterReplacement(string s, int k) {
}
};
#+end_src