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
kcharacters ofword. - Add any
kcharacters to the end ofword.
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
Input
word = "abacaba", k = 3Output
2After 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
Input
word = "abacaba", k = 4Output
1After 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.