> For the complete documentation index, see [llms.txt](https://gl01.gitbook.io/gfg-editorials/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gl01.gitbook.io/gfg-editorials/2023/11-2023-nov-13/14-check-if-strings-are-rotations-of-each-other-or-not.md).

# 14. Check if strings are rotations of each other or not

The problem can be found at the following link: [Question Link](https://www.geeksforgeeks.org/problems/check-if-strings-are-rotations-of-each-other-or-not-1587115620/1)

![](https://badgen.net/badge/Level/Basic/green)

## My Approach

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 and Auxiliary Space Complexity

* **Time Complexity**: `O(N)`, where `N` is the length of `s1`.
* **Auxiliary Space Complexity**: `O(N)`, as we create a new string by concatenation.

## Code (C++)

```cpp
class Solution {
public:
    bool areRotations(string s1, string s2) {
        string s = s1 + s1;
        return s.find(s2) != -1;
    }
};
```

## Contribution and Support

For discussions, questions, or doubts related to this solution, please visit our [discussion section](https://github.com/getlost01/gfg-potd/discussions). 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](https://github.com/getlost01/gfg-potd) repository.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gl01.gitbook.io/gfg-editorials/2023/11-2023-nov-13/14-check-if-strings-are-rotations-of-each-other-or-not.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
