Make Every Password Block a Palindrome

Quick Overview

Implement `minimum_palindromic_block_changes(password, k)`. Work through the function contract, boundary cases, correctness argument, and time and space complexity expected in a production-quality solution.

Make Every Password Block a Palindrome

Company: Citadel

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

Implement `minimum_palindromic_block_changes(password, k)`. The password length is a multiple of `k`. Partition it into consecutive blocks of exactly `k` characters. You may replace any character with any lowercase English letter. Return the minimum number of replacements needed so that every block is a palindrome. ### Constraints - `1 <= len(password) <= 200000` - `1 <= k <= len(password)` and `len(password) % k == 0` - `password` contains only lowercase English letters. ### Examples - `"abcaabba"`, `k = 4` returns `1`: change the first block `abca` to a palindrome; `abba` already is one. - `"abcdef"`, `k = 3` returns `2`: each of `abc` and `def` needs one mirrored-pair change. - `"aaaa"`, `k = 1` returns `0`. ```hint Exercise both parity cases Test odd and even block lengths, including `k = 1` and an already-palindromic block. ``` ```hint Check edits at different locations Include blocks whose disagreements occur near the ends, near the center, and in more than one place. ```

Quick Answer: Implement `minimum_palindromic_block_changes(password, k)`. Work through the function contract, boundary cases, correctness argument, and time and space complexity expected in a production-quality solution.

|Home/Coding & Algorithms/Citadel
Citadel logo
Citadel
Mar 27, 2026, 12:00 AM
mediumSoftware EngineerTake-home ProjectCoding & Algorithms
0
0

Implement minimum_palindromic_block_changes(password, k).

The password length is a multiple of k. Partition it into consecutive blocks of exactly k characters. You may replace any character with any lowercase English letter. Return the minimum number of replacements needed so that every block is a palindrome.

Constraints

  • 1 <= len(password) <= 200000
  • 1 <= k <= len(password) and len(password) % k == 0
  • password contains only lowercase English letters.

Examples

  • "abcaabba" , k = 4 returns 1 : change the first block abca to a palindrome; abba already is one.
  • "abcdef" , k = 3 returns 2 : each of abc and def needs one mirrored-pair change.
  • "aaaa" , k = 1 returns 0 .

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...