FastPrepMinimum Changes for Palindromic Blocks
Problems/Minimum Changes for Palindromic Blocks

Minimum Changes for Palindromic Blocks

Citadel logoCitadel● EasyINTERNFULLTIMENEW GRADOAPHONE SCREENONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interviewer asked: "Make each block of k characters palindromic. The final block may be shorter."

The signature, lowercase alphabet, numeric bounds, and examples are specified here. Blocks are independent and do not have to become equal.

The judged task matches the report at about 96%.

You are given a lowercase string password and a positive integer k. Partition the string into consecutive, non-overlapping blocks of k characters, starting at index 0. The last block may have fewer than 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 = 4return = 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 = 3return = 2

The blocks abc and def each have one mismatched mirrored pair, so each needs one change.

Example 3

password = "aaaa"k = 1return = 0

Every one-character block is already a palindrome.

Example 4

password = "abcde"k = 3return = 2

The blocks are abc and de. Each has one mismatched mirrored pair, so the total is 2.

Constraints

  • 1 <= password.length <= 200000
  • 1 <= k <= password.length
  • password contains only lowercase English letters.
  • The final block may have fewer than k characters.

More Citadel problems

  • Portfolio Tickers with Constant-Time Random PickPHONE SCREEN · Seen Nov 2026
  • Square Root FunctionPHONE SCREEN · Seen Oct 2026
  • Reachable Transfer PositionsPHONE SCREEN · Seen Oct 2026
All Citadel interview questionsSee Citadel hiring insights
Saved
class Solution {
    public int minChangesForPalindromicBlocks(String password, int k) {
      // write your code here
    }
}
Checking account…