Member-only story
Longest Repeating String After K Replacement Using Python 🐍| Coding Interview | Sliding Window Pattern
We will discuss a little bit about a naive approach to solving this problem before moving on to an efficient solution. The strategy for this problem is similar to the Smallest Subarray With a Given Sum. I have tried to explain these concepts in simple terms, hope you find the effort useful.
This problem has been asked by Meta, Uber, Amazon, and Adobe.
If you are preparing for an upcoming coding interview you may want to check out my 30 Days preparation plan, this article belongs to that plan.
Contents
Description
Given a string S with only uppercase letters and you are allowed to make at most K replacements with other uppercase letters. Find the length of the longest substring containing the same letter after replacement.
Example 1:Input: S = ABBCAB, K = 2
Output: 5Explanation: The longest substring after at most 2 replacements is BBBBB from BBCAB where we replaced 'C' and…