12. Check if string is rotated by two places
Last updated
Last updated
The problem can be found at the following link: Question Link
To check if a string is rotated by two places,
I compare the original string s1
and check if the first string is equal to either of the two possible rotations of the second string s2
.
The rotations are done by taking two characters from the end and placing them at the beginning, or taking two characters from the beginning and placing them at the end.
Time Complexity: O(N)
, where N
is the length of the strings.
Auxiliary Space Complexity: O(1)
as we use a constant amount of additional space.
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.