> For the complete documentation index, see [llms.txt](https://maksimdan.gitbook.io/interview-practice-problems/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://maksimdan.gitbook.io/interview-practice-problems/leetcode_sessions/567-permutation-in-string.md).

# 567 Permutation in String

Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string's permutations is the substring of the second string.

```
Input:s1 = "ab" s2 = "eidbaooo"
Output:True
Explanation: s2 contains one permutation of s1 ("ba").
```

```
Input:s1= "ab" s2 = "eidboaoo"
Output: False
```

Note: 1. The input strings only contain lower case letters. 2. The length of both given strings is in range \[1, 10,000].

**Brute Force Approach**: Every substring of length |s1| in |s2| and find at least one instance of where the sorted substring == sorted s1.

**Time Complexity**: Let s1 be len(s1) and s2 be len(s2). O((s1-s2)\*s1logs1 + s1(s1-s2)) for sorting each substring and string comparison.

```python
def checkInclusion(self, s1, s2):
    """
    :type s1: str
    :type s2: str
    :rtype: bool
    """

    sorted_s1 = sorted(s1)
    go_till = len(s2) - len(s1) + 1
    for i in range(0, go_till):
        if sorted_s1 == sorted(s2[i:i+len(s1)]):
            return True

    return False
```


---

# 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, and the optional `goal` query parameter:

```
GET https://maksimdan.gitbook.io/interview-practice-problems/leetcode_sessions/567-permutation-in-string.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
