# Check String Permutation

{% tabs %}
{% tab title="Scala" %}

```scala
import scala.collection.mutable.Map

def isPermutation(s1: String, s2: String): Boolean = {
  if (s1.length != s2.length) false
  else if (s1.isEmpty) true
  else {
    val charMap = Map[Char, Int]() withDefaultValue 0
    for (i <- 0 until s1.length; j <- 0 until s2.length) {
      charMap(s1(i)) += 1
      charMap(s2(j)) -= 1
    }
    charMap.values.forall(_ == 0)
  }
}

isPermutation("", "")
isPermutation("abcd", "dcba")
isPermutation("abcd", "ecba")
```

{% endtab %}

{% tab title="Second Tab" %}

{% endtab %}
{% endtabs %}


---

# Agent Instructions: 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://blog.bernardw.com/problems/check-string-permutation.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.
