Input: str1 = “abcabcabc”, str2 = “abc”
Concatenating the string str2 thrice generates the string (“abc” + “abc” + “abc” = ) “abcabcabc”.
Therefore, the required output is Yes.
Input: str1 = “abcabcab”, str2 = “abc”
Approach: Follow the steps below to solve the problem:
- Traverse the strings str1 and str2.
- For each character of str1 and str2, check if str1[i] == str2[i % M] or not.
- If found to be false for any character, print “No”.
- Otherwise, print “Yes”.
Below is the implementation of the above approach:
Time Complexity: O(N)
Auxiliary Space: O(1)
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 given string is a substring of string formed by repeated concatenation of z to a
- Check if concatenation of any permutation of given list of arrays generates the given array
- Longest palindromic String formed using concatenation of given strings in any order
- Minimum flips required to convert given string into concatenation of equal substrings of length K
- Minimize cost to convert given string into concatenation of equal substrings of length K
- Check if the concatenation of first N natural numbers is divisible by 3
- Longest palindromic string formed by concatenation of prefix and suffix of a string
- Minimum characters to be replaced to make a string concatenation of a K-length palindromic string
- Check if a given string can be converted to another by given possible swaps
- Check if the given string is shuffled substring of another string
- Minimum concatenation required to get strictly LIS for the given array
- Ropes Data Structure (Fast String Concatenation)
- Count of pairs of strings whose concatenation forms a palindromic string
- Lexicographical concatenation of all substrings of a string
- Print Concatenation of Zig-Zag String in 'n' Rows
- Check if it is possible to convert one string into another with given constraints
- Check if a string can be converted to another by swapping of adjacent characters of given type
- Check if a string can be obtained by rotating another string 2 places
- Check if a string can be repeated to make another string
- Check if a string can be converted to another string by replacing vowels and consonants
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.