Tap here to switch tabs
Problem
Submissions

Problem: Minimum Number of Operations to Make Word K-Periodic

med
30 min
Try to solve the Minimum Number of Operations to Make Word K-Periodic problem.

Statement

You are given a string word of length n and an integer k, where n is divisible by k.

In a single operation, you can choose two indices i and j such that both i and j are multiples of k, and replace the substring of length k starting at index i with the substring of length k starting at index j.

A string is considered k periodic if every non overlapping substring of length k is identical.

Return the minimum number of operations needed to make word k periodic.

Constraints:

  • 1≤1 \leq n ==== word.length ≤105\leq 10^5

  • 1≤1 \leq k ≤\leq word.length

  • k divides word.length.

  • word consists only of lowercase English letters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Number of Operations to Make Word K-Periodic

med
30 min
Try to solve the Minimum Number of Operations to Make Word K-Periodic problem.

Statement

You are given a string word of length n and an integer k, where n is divisible by k.

In a single operation, you can choose two indices i and j such that both i and j are multiples of k, and replace the substring of length k starting at index i with the substring of length k starting at index j.

A string is considered k periodic if every non overlapping substring of length k is identical.

Return the minimum number of operations needed to make word k periodic.

Constraints:

  • 1≤1 \leq n ==== word.length ≤105\leq 10^5

  • 1≤1 \leq k ≤\leq word.length

  • k divides word.length.

  • word consists only of lowercase English letters.