Sliding Window pattern
Longest Repeating Character Replacement
Given a string and a budget of k character changes, find the length of the longest substring made of a single repeated character after performing at most k replacements. Watch it run step by step, then write your own pseudocode and get it checked by AI.
- LeetCode 424
- Medium
- 2 approaches
Sign in with Google or GitHub and you land straight on this page. DSA comes with the all labs plan and every ChaiCode batch.
Sliding WindowLeetCode 424
Medium
From the first idea to the best one
- 01 Brute force · extend from every start O(n²)O(26) space
- 02 Optimized · variable window O(n)O(26) space
What you will learn
- How to read Longest Repeating Character Replacement and spot the sliding window pattern in it
- Brute force · extend from every start: O(n²) time, O(26) space
- Optimized · variable window: O(n) time, O(26) space
- The pseudocode for each approach, its line lit as the animation runs
- Practice: write your own pseudocode and get it checked
More Sliding Window
See Longest Repeating Character Replacement run, step by step
Sign in and this page opens on the animation, with all 8 Sliding Window problems beside it.
DSA comes with the all labs plan and every ChaiCode batch.