Given two strings a and b, the task is to check how many times the string a can be repeated to generate the string b. If b cannot be generated by repeating a then print -1.
Input: a = “geeks”, b = “geeksgeeks”
“geeks” can be repeated twice to generate “geeksgeeks”
Input: a = “df”, b = “dfgrt”
- If len(b) % len(a) != 0 then print -1 as b cannot be generated by repeating a.
- Else set count = len(b) / len(a) and repeat a count number of times.
- If a = b then print count.
- Else print -1.
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
- Check if any permutation of string is a K times repeated string
- Longest sub string of 0's in a binary string which is repeated K times
- Minimum changes required to make first string substring of second string
- Make a palindromic string from given string
- String which when repeated exactly K times gives a permutation of S
- Queries for characters in a repeated string
- Find the first repeated word in a string
- Find the first repeated character in a string
- Python | Check if given string can be formed by concatenating string elements of list
- 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
- Maximum repeated frequency of characters in a given string
- Find repeated character present first in a string
- Remove Duplicate/Repeated words from 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.