AO
Back

Min Changes to Make Password a K-Periodic Palindrome

OAAsync OALast reported September 2025Low Frequency

Problem Overview

Two problems in 75 minutes, online assessment. This is one of them.

You are given a string currentPassword and an integer k. Change currentPassword into a newPassword of the same length that meets two requirements:

  1. newPassword is a palindrome.
  2. newPassword repeats with period k: newPassword[i] == newPassword[i + k] for every valid i.

Return the minimum number of characters that must change to turn currentPassword into newPassword.

Input:  currentPassword = "abzzbz", k = 3
Output: 1
Explanation: "abzzbz" -> "zbzzbz" changes one character.

Constraints

  • 1 <= k < length(currentPassword) <= 2 * 10^5
  • The length of currentPassword is divisible by k.
  • currentPassword contains only lowercase letters.

Confirm on the day

  • Letter case. Two reports say lowercase letters only; one says the password mixes upper and lower case and comparisons are case-sensitive. Ask, or read the prompt: comparing characters exactly as they are handles both.
  • Which condition. One candidate, recalling the problem later and saying they had partly forgotten it, describes it as "starting from the first position, every k letters form a palindrome", which reads as each block of k being its own palindrome. The report that posts the prompt word for word (with the example and constraints above) and a second independent report both give the two requirements above: the whole password is a palindrome and it repeats every k characters. Check which one your prompt states.

Approach Trade-offs

Approaches actually attempted in reports — including ones that lost candidates time. Pick deliberately.
ApproachNotes
Union-find over the period and mirror pairsPosted in a thread as a JavaScript solution it labels O(n) (strictly O(n α(n))): union i with i + k and i with n - 1 - i, then keep the most common character per root. Same answer as grouping remainders r and k - 1 - r directly, with more code; the direct grouping needs no union-find arrays.

What Reports Emphasize

Common mistakes: A solution that is too slow for every test case: one candidate says the problem is not hard but passing all test cases needs a fairly fast solution.

What passers do: Near-linear time: the union-find solution posted in a thread labels itself O(n) time and O(n) space (strictly O(n α(n)) time).

Why people fail: Running out of the 75 minutes: one candidate found both problems not very hard but solved neither.

Practice

Write your own against 12 test cases, or read the worked solution — approach, complexity, and code that runs.

Prepping for Citadel with friends?

Send them this page. It is free to read, no account needed.

More Citadel Questions

Free preview

Every question in the Citadel catalog gets this depth

What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 62 Citadel questions, refreshed monthly from new candidate reports.

$59/mo — or $50/mo with the 3-month pass · cancel anytime
Citadel · OA · Reported 3× across candidate reports
Is this helpful?