VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 04: Sliding window

Lesson 4.4 of 10 in this module Unrolled Pro

Longest Repeating Character Replacement

The longest substring you can turn into one repeated letter with at most k changes. From trying every substring (O(n²) with counts), to one window per target letter (O(26·n)), to a single window that tracks the most frequent letter and never needs to lower it. Then large alphabets, returning the substring, and finding stable stretches in noisy model predictions.

about 10 min 4 Python examples 2 quick checks

Problem. You may change at most k characters of s (uppercase letters) to any other letter. Return the length of the longest substring that can be made of one repeated letter.

text
s = "ABAB",    k = 2   →   4     (change both A's or both B's)
s = "AABABBA", k = 1   →   4     ("AABA" → "AAAA")

ML context. Replace "letters" with per-frame predictions and k with a noise budget: "the longest stretch where the model predicts one class, allowing k glitches" is how you smooth segment labels in speech, video or activity recognition, where a single misclassified frame shouldn't split one event into two.


1. Step 1: Clarify

That's the preview. Modules 00–01 are free; this lesson is part of Unrolled Pro.
Staff AI & Pro Tier Lesson

Unlock "Longest Repeating Character Replacement"

The foundations are free forever. Unrolled Pro unlocks the complete lesson, production architectures, and 55 battle-tested ML system design case studies.

Everything included with Pro:
All 234+ Deep-Dive Lessons across transformer internals, inference, RAG & agents
55 Staff-Level ML & System Design Case Studies with mathematical capacity estimates
AI Engineer Sheet & Exercises with worked solutions, self-checks, and code
100 Landmark Research Papers guided walkthroughs & progress tracking
14-Day Money-Back Guarantee — 100% full refund if you aren't satisfied
View Plans & Unlock All Lessons

From ₹167/mo (~$2/mo) · Cancel anytime · Instant activation

100% Risk-Free: 14-day no-questions-asked money-back guarantee