Skip to content

Interview question · Sliding window

Longest Repeating Character Replacement

Longest Repeating Character Replacement is a Medium question that uses the sliding window pattern. PrepKit files it under Sliding window.

PrepKit lists the title and a link. The problem statement stays on the original site.

Checking your saved items

Copyright and correction requests

Source content: English

Key facts

Topic
Sliding window
Pattern
sliding window
Difficulty
Medium
Appears in
Blind 75, NeetCode 150
Website
leetcode.com
License
MIT License

How to use it

  1. Read the problem on the original site.
  2. Try it on your own before you look at hints or solutions.
  3. Then work through a related question with the same pattern.

About the Sliding window pattern

PrepKit study notes. PrepKit editors wrote these as general advice. They are not taken from the problem or from any published solution.

What it is
Keeping a contiguous range over an array or string and moving its edges forward while you update a running state.
How to recognize it
The question asks for the longest, shortest or best contiguous subarray or substring that meets a condition.
Common pitfalls
Recomputing the whole window at every step, shrinking it at the wrong moment, and using it when negative values break the rule for growing and shrinking.

Pages that include this

Common questions

Where can I practice Longest Repeating Character Replacement?

Open it on leetcode.com. PrepKit links there and does not copy the problem.

What pattern does Longest Repeating Character Replacement use?

PrepKit files it under sliding window, at Medium difficulty.

Source and license

Source and license

License:
MIT License
Author:
Enzo Davico
Source version:
5c033cb
Last checked against the source:
Changes:
PrepKit kept only each problem's title, pattern, difficulty, list membership, and LeetCode link. Solutions, quizzes, Anki content, NeetCode links, videos, and ordering are not copied.
Visit original source
Full license and copyright notice

MIT License Copyright (c) 2023 Enzo Davico Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.