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:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check if a string can be obtained by rotating another string 2 places
- Check if a string can be formed from another string using given constraints
- 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 d places
- Check if a string can be formed from another string by at most X circular clockwise shifts
- Check if a string can be obtained by appending subsequences of another string
- Check if one string can be converted to another
- Check if a string can be converted to another by swapping of adjacent characters of given type
- Check if a string can be transformed to another by sorting substrings
- Check if permutaion of one string can break permutation of another
- Check if a given string can be converted to another by given possible swaps
- Check if any permutation of string is a K times repeated string
- Check if given string is a substring of string formed by repeated concatenation of z to a
- Length of longest substring to be deleted to make a string equal to another string
- Count occurrences of a string that can be constructed from another given string
- Make a string from another by deletion and rearrangement of characters
- Count of strings that can be formed from another string using each character at-most once
- Longest sub string of 0's in a binary string which is repeated K times
- Check if a string is a scrambled form of another string
- Check if a string is concatenation of another given 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.