Assume you have a method isSubstring which checks if one word is a substring
of another. In C# you can use string.contains. Given two strings, str1 and str2, write code to check if str2 is a rotation of str1, using only one call to isSubstring / string.contains (e.g. “olAam” is a rotation of “Aamol”).
If we imagine that str2 is a rotation of str1, then we can ask what the rotation point is. For example, if you rotate Aamol after “Aam”, you get “olAam”. In a rotation, we
cut str1 into two parts x and y, and rearrange them to get str2.
str1 = xy = Aamol
str2 = yx = olAam
So, we need to check if there’s a way to split str1 into x and y such that xy = str1 and yx = str2. Regardless of where the division between x and y is, we can see that yx will always be a substring of xyxy. That is str2 will always be a substring of str1str1. That’s how we solve the problem: simply do isSubstring(str1str1, str2).