Minimum Changes for Palindromic Blocks
Reported by candidates from Citadel's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The edge case that kills a naive solution on this Citadel OA, reported August 2026, is the middle character of an odd-length block. Plenty of candidates overthink it and reach for DP or try to unify blocks. You don't need any of that. Split the password into chunks of k, count mismatched mirrored pairs in each, and sum them. It's a simple array and string scan, and the trap is in the details, not the algorithm. If you blank under the clock, StealthCoder runs invisibly during the live OA and hands you the clean loop so you can still ship a correct answer.
The problem
You are given a lowercase string password and a positive integer k. The string length is divisible by k, so it is partitioned into consecutive, non-overlapping blocks of exactly k characters. Change as few characters as possible so that every block is a palindrome. Blocks are independent and do not need to become equal to one another. Return the minimum number of changed positions. Function minChangesForPalindromicBlocks(password: String, k: int) → int Examples Example 1 password = "abcaabba" k = 4 return = 1 The blocks are abca and abba. The second is already palindromic; changing either b or c in the first block is sufficient. Example 2 password = "abcdef" k = 3 return = 2 The blocks abc and def each have one mismatched mirrored pair, so each needs one change. Example 3 password = "aaaa" k = 1 return = 0 Every one-character block is already a palindrome. Constraints 1 <= password.length <= 200000 1 <= k <= password.length password.length % k == 0 password contains only lowercase English letters.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is that blocks are independent and each mismatched mirrored pair costs exactly one change, since you can overwrite either character to match the other. So for each block starting at index b, compare password[b+i] with password[b+k-1-i] for i from 0 to k/2 - 1, and add one per mismatch. Total work is O(n) time and O(1) space. The pitfalls: looping i over the whole block and double counting every pair, miscounting when k is odd (the middle char has no partner and costs nothing), and k = 1, where the answer is always 0. Don't build substrings in a hot loop at n = 200000 either. Index math is cleaner. If the index arithmetic slips mid-assessment, StealthCoder is the safety net that shows the correct bounds while you stay in flow.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Minimum Changes for Palindromic Blocks cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Citadel's OA.
Citadel reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Minimum Changes for Palindromic Blocks FAQ
How hard is this Citadel OA problem really?+
Easy once you see it. It's a single pass with index math. The difficulty is not the algorithm, it's avoiding off-by-one errors in the mirrored index and not overcomplicating it with DP or block-equalizing logic the problem explicitly rules out.
What's the trick to minimum changes for palindromic blocks?+
Each mismatched mirrored pair inside a block needs exactly one change, because you can edit either character. Blocks are independent, so sum the mismatches across all blocks. No interaction between blocks, no greedy choice of letters needed.
What's the time complexity I should aim for?+
O(n) time and O(1) extra space, where n is the password length up to 200000. You touch each character at most once. Anything quadratic from repeated substring creation or reversing each block is unnecessary and risky at this size.
Which edge cases should I test before submitting?+
Test k = 1 (answer 0), k equal to the full length (one big palindrome check), odd k where the middle character is ignored, and a string that's already palindromic per block. Also run the three given examples: 1, 2, and 0.
How do I prepare for this in 48 hours?+
Write the double loop by hand twice: outer over block starts stepping by k, inner over half the block comparing start+i with start+k-1-i. Then practice general palindrome two-pointer problems. This pattern shows up often in string OAs, so the muscle memory pays off.