Company: Turing
Difficulty: medium
TURING - Problem 1 You are given a string word of length n and an integer k such that k divides n. In one operation, you can choose any two indices i and j, both divisible by k, and swap the substring of length k starting at i with the substring of length k starting at j. Specifically, you replace substring word[i..i+k-1] with the substring word[j..j+k-1]. Your goal is to determine the minimum number of operations needed to transform word into a k-periodic string. A string is considered k-periodic if there exists a string s of length k such that the entire word can be constructed by repeating s multiple times. For instance, if word == \"ababab\", then word is 2-periodic for s = \"ab\". Examples Example 1: Input: word = \"codeninacode\", k = 4 Output: 1 You can achieve a 4-periodic string by selecting i = 4 and j = 0. After this operation, the word becomes \"codecodecode\". Example 2: Input: word = \"codencoode\", k = 2 Output: 2 You can achieve a 2-periodic string by performing the fol