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:
- Minimum changes required to make first string substring of second 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 converted to another string by replacing vowels and consonants
- Find the first repeated character in a string
- Queries for characters in a repeated string
- String which when repeated exactly K times gives a permutation of S
- Find the first repeated word in a string
- Check if a string can become empty by recursively deleting a given sub-string
- Check if a string can be obtained by rotating another string 2 places
- Number of subsequences as "ab" in a string repeated K times
- Count occurrences of a character in a repeated string
- Remove Duplicate/Repeated words from String
- Find repeated character present first in a string
- Check if a string can be formed from another string using given constraints
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.