Skip to content

Practice Minimum Changes to Make K Semi-palindromes

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#2911
LeetCode Problem

Minimum Changes to Make K Semi-palindromes

Problem Statement

Split s into exactly k nonempty contiguous pieces and change as few letters as possible so each piece is a semi-palindrome. A string of length L is semi-palindromic when some positive divisor d of L with d < L makes every residue-class subsequence a palindrome: for each offset from 0 to d-1, read positions offset, offset+d, offset+2d and so on. A length-one string cannot qualify. Return the minimum total letter replacements.

Source: Minimum Changes to Make K Semi-palindromes on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "abcac", k = 2
Output
1

# Example 2

Input
s = "abcdef", k = 2
Output
2

# Example 3

Input
s = "aabbaa", k = 3
Output
0

Constraints

2 <= s.length <= 200
1 <= k <= s.length / 2
s contains only lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Minimum Changes to Make K Semi-palindromes.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.