Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Longest Repeating Char Replace

Python data engineering interview problem. Difficulty: intermediate. Pattern: Sliding Window. About 14 minutes. Part of the Pro drill bank.

Longest same-letter window after at most k replacements. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.

Implement character_replacement(s: str, k: int) -> int.

Constraints

  • Only uppercase English letters in tests.
  • k >= 0.

Examples

Input: character_replacement('ABAB', 2) Output: 4 Replace both B or both A.

Topics: lakebench, python, window, replace.

More Python interview questions · All interview problems · Learn data engineering

intermediate

Longest Repeating Char Replace

Interview-style drill: Longest same-letter window after at most k replacements.

Implement `character_replacement(s: str, k: int) -> int`. Example: `"ABAB", 2` → `4`. Keep the harness.