Minimum Time to Revert Word to Initial State I

You are given a 0-indexed string word and an integer k.

At every second, you must perform the following operations:

  • Remove the first k characters of word.
  • Add any k characters to the end of word.

Note that you do not necessarily need to add the same characters that you removed. However, you must perform both operations at every second.

Return the minimum time greater than zero required for word to revert to its initial state.

Example 1
Inputword = "abacaba", k = 3
Output2
After removing "aba" and adding "bac", then removing "cab" and adding "aba", word reverts to its initial state in 2 seconds, which is the minimum time greater than zero.
Example 2
Inputword = "abacaba", k = 4
Output1
After removing "abac" and adding "caba" at the 1st second, word reverts to its initial state, so the minimum time is 1 second.

Constraints

  • 1 <= word.length <= 50
  • 1 <= k <= word.length
  • word consists only of lowercase English letters.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate