Given two strings s1 and s2, we need to find number of common base strings of two. A substring of a string s is called base string if repeated concatenation of the substring results in s.
Input : s1 = "pqrspqrs" s2 = "pqrspqrspqrspqrs" Output : 2 The two common base strings are "pqrs" and "pqrspqrs". Input: s1 = "bbb" s2 = "bb" Output: 1 There is only one common base string which is "b".
The maximum possible length of common base string is equal to length of smaller of two strings. So we run a loop that considers all prefixes of smaller string and for every prefix checks if it is a common base.
Below is the implementation of the following approach
Time Complexity : O(min(n1, n2) * (n1 + n2))
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.
- Interleaving of two given strings with no common characters
- Print common characters of two Strings in alphabetical order
- Python code to print common characters of two Strings in alphabetical order
- Check if two strings have a common substring
- Count common subsequence in two strings
- Check if there is any common character in two given strings
- Count common characters in two strings
- Program to check if a number belongs to a particular base or not
- Check if a number is in given base or not
- Count of primes after converting given binary number in base between L to R
- Count the number of common divisors of the given strings
- Convert all substrings of length 'k' from base 'b' to decimal
- Decode an Encoded Base 64 String to ASCII String
- LCS (Longest Common Subsequence) of three strings
- Common characters in n strings
- Longest common anagram subsequence from N strings
- Construct an Array of Strings having Longest Common Prefix specified by the given Array
- Program to find Greatest Common Divisor (GCD) of N strings
- Length of longest common prefix possible by rearranging strings in a given array
- Longest Common Substring in an Array of Strings
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.