Minimize changes for k-periodic palindrome
CitadelSoftware Engineer · Online AssessmentLast updated
This question evaluates understanding of string algorithms and combinatorial reasoning, focusing on palindrome properties combined with k-periodicity and the ability to minimize character changes under global constraints.
Question
Given a string currentPassword (length N) and an integer k (1 ≤ k < N, N ≤ 2·10^5, lowercase letters, N divisible by k), find the minimum number of character changes needed to transform currentPassword into a newPassword such that (
- newPassword is a palindrome and (
- newPassword[i] = newPassword[i + k] for all valid i (k-periodic). Return that minimum number of changes.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.