Given a string str and an integer K, the task is to check whether the given string is K-periodic. A string is k-periodic if the string is a repetition of the sub-string str[0 … k-1] i.e. string “ababab” is 2-periodic. Print Yes if the given string is k-periodic else print No.
Input: str = “geeksgeeks”, k = 5
Given string can be generated by repeating the prefix of length k i.e. “geeks”
Input: str = “geeksforgeeks”, k = 3
Approach: Starting with the sub-string str[k, 2k-1], str[2k, 3k-1] and so on, check whether all of these sub-strings are equal to the prefix of the string of length k i.e. str[0, k-1]. If the condition is true for all such sub-strings then print Yes else print No.
Below is the implementation of the above approach:
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- String slicing in Python to check if a string can become empty by recursive deletion
- Check if a string can be formed from another string by at most X circular clockwise shifts
- Check if a string can be converted to another string by replacing vowels and consonants
- Check if a string can be obtained by rotating another string 2 places
- Check if a string can become empty by recursively deleting a given sub-string
- Check if any permutation of string is a K times repeated string
- Check if left and right shift of any string results into given string
- Queries to check if string B exists as substring in string A
- Check if a string can be obtained by rotating another string d places
- Check if a string can be formed from another string using given constraints
- Check if the given string is shuffled substring of another string
- Check whether second string can be formed from characters of first string
- Check if a string can be repeated to make another string
- Check if a string contains a palindromic sub-string of even length
- Check if a given string is sum-string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.