The Blind 75 Leetcode Series: Longest Repeating Character Replacement

Jonathan Chao
4 min readNov 7, 2023
Photo by Chris Ried on Unsplash

Today, we are working on 424. Longest Repeating Character Replacement

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.

In this problem, we are given a string and an int. The string has a variety of 26 uppercase english letters. k denotes number of times we can switch the letter in order to get the longest substring of the same letter.

It doesn’t specify which letter we are keeping or switching. We just need to keep track of number of letters we have switched.

Before moving on, we need to clarify some things:

  1. how long can the string be?
  2. can k be larger than the length of the string?
  3. and we can double check on the uppercase english letter criteria

--

--

Jonathan Chao
Jonathan Chao

Written by Jonathan Chao

I am a software developer who has been in this industry for close to a decade. I share my experience to people who are or want to get into the industry