14. Check if strings are rotations of each other or not
Last updated
Last updated
The problem can be found at the following link: Question Link
To check if two strings, s1
and s2
, are rotations of each other,
I concatenate s1
with itself to create a new string s
.
Then, I check if s2
is a substring of s
using the find
function. If the index is not -1, then s2
is a rotation of s1
.
Time Complexity: O(N)
, where N
is the length of s1
.
Auxiliary Space Complexity: O(N)
, as we create a new string by concatenation.
For discussions, questions, or doubts related to this solution, please visit our discussion section. We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star to the getlost01/gfg-potd repository.