Skip to content

Practice Minimum Time to Revert Word to Initial State II

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

Hard#3031
LeetCode Problem

Minimum Time to Revert Word to Initial State II

Problem Statement

Given word and k, every second remove the first k characters and append any k characters to the end. The appended characters need not equal the removed characters, but both actions must occur each second. Return the smallest positive number of seconds after which the string can equal its original value.

Source: Minimum Time to Revert Word to Initial State II on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
word = "abacaba", k = 3
Output
2

# Example 2

Input
word = "abacaba", k = 4
Output
1

# Example 3

Input
word = "abcbabcd", k = 2
Output
4

Constraints

1 <= word.length <= 10^6
1 <= k <= word.length
word consists only of lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Minimum Time to Revert Word to Initial State II.

Review your practice with PhantomCodeAI

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