Back to problems

Minimum Character Changes to Make Every k-Length Block a Palindrome

Algorithm · Ramp · Medium

Given a string password of length n and an integer k, you are guaranteed that n is divisible by k. Divide password into n / k consecutive blocks of length k, starting from index 0: block 0 covers indices 0 through k - 1, block 1 covers indices k through 2k - 1, and so on. A block is valid if it is a palindrome. For a length-k block b, this means $$b[j] = b[k - 1 - j]$$ for every $$j$$ such that $$0 \le j < \lfloor k / 2 \rfloor$$. When k is odd, the middle character does not…

Checking your access…