As reported: Amazon SDE loop (2025; offer), round 2 — two Leadership Principle questions and two DSA problems: Longest Substring with At Most K Replacements, then detecting and removing a cycle in a linked list.
You are given a string s of uppercase English letters and an integer k. You may choose any character of the string and change it to any other uppercase letter, at most k times in total. Return the length of the longest substring containing one repeated letter you can get.
This is LeetCode 424 — Longest Repeating Character Replacement.
Example 1
s = "ABAB", k = 2
Output: 4
Example 2
s = "AABABBA", k = 1
Output: 4 (change the A at index 4: "AABBBBA" contains "BBBB")
Constraints: 1 ≤ s.length ≤ 10⁵; uppercase English letters; 0 ≤ k ≤ s.length.
Code runner format: one JSON value per line, in order: s, k (LeetCode's test-case format). Implement characterReplacement(s, k); the harness prints the length.