Make Every Password Block a Palindrome
Company: Citadel
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Online Assessment
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.
Constraints
- 1 <= len(password) <= 200000.
- 1 <= k <= len(password), and len(password) is a multiple of k.
- password contains only lowercase English letters.
Examples
Input: ('a', 1)
Expected Output: 0
Explanation: A one-character block is already a palindrome.
Input: ('aaaa', 1)
Expected Output: 0
Explanation: Every length-one block needs zero replacements.
Hints
- Test both odd and even block lengths, including k = 1 and an entire-password block.
- Include already-palindromic blocks and blocks with disagreements near the ends and near the center.
- Use several consecutive blocks so zero-, one-, and multiple-change blocks contribute to one total.
Community answers
Answer by testingprachub