Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

34. Longest Repeating Character Replacement

MediumDay 11 of 60Sliding Window

You are given a string s of uppercase English letters and an integer k. You may change at most k characters of s into any other uppercase letter. Return the length of the longest substring that can be made of a single repeated letter after these changes.

Example 1
Input: s = "ABAB", k = 2
Output: 4
Change both As to B (or both Bs to A) to get four equal letters.
Example 2
Input: s = "AABABBA", k = 1
Output: 4
Change the A at index 3 to get "BBBB" from index 3 to 6.
Constraints
  • 1 <= s.length <= 10^5
  • `s` has only uppercase English letters
  • 0 <= k <= s.length
Hints
Frequently asked at: Google, Amazon, Uber, PhonePe
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min