14. Check if strings are rotations of each other or not
The problem can be found at the following link: Question Link
My Approach
To check if two strings, s1
and s2
, are rotations of each other,
I concatenate
s1
with itself to create a new strings
.Then, I check if
s2
is a substring ofs
using thefind
function. If the index is not -1, thens2
is a rotation ofs1
.
Time and Auxiliary Space Complexity
Time Complexity:
O(N)
, whereN
is the length ofs1
.Auxiliary Space Complexity:
O(N)
, as we create a new string by concatenation.
Code (C++)
Contribution and Support
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.
Last updated