As reported: Zscaler Senior Software Engineer interview (Bangalore, 2026): an introduction, about 20 minutes on previous projects, then this single DSA question. A solution that runs once per letter (O(26·n)) was not what the interviewer wanted: they looked for a more efficient approach that solves it in one pass.
This is LeetCode 424 — Longest Repeating Character Replacement. Our write-up: /longest-repeating-character-replacement.
Given a string s of uppercase English letters and an integer k, you may change any character to any other uppercase letter, at most k times in total. Return the length of the longest substring containing a single repeated letter that you can get.
Example 1
s = "ABAB", k = 2
Output: 4 (replace both A's or both B's)
Example 2
s = "AABABBA", k = 1
Output: 4 (replace the middle A: "AABBBBA" has "BBBB")
Constraints: 1 ≤ s.length ≤ 10^5, s has only uppercase letters, 0 ≤ k ≤ s.length.
Code runner format: two JSON values, one per line: s and k. Implement characterReplacement(s, k).