# Strings

## Runtime analysis

Similar to [Arrays](/data-structures/arrays.md)with some differences:

1. Concatenation: $$O(m + n)$$
2. Find substring: $$O(m \times n)$$ (can be improved using Rabin Karp)
3. Slice: $$O(m)$$
4. Split by token: $$O(m + n)$$
5. Strip: $$O(n)$$

## Corner cases

1. Empty strings
2. Strings with 1 or 2 characters
3. Strings with repeated characters
4. Strings with only distinct characters

## Take note...

1. Input character set (ASCII, UTF-8, all lowercase alphabets, etc.)
2. Case sensitivity

## Techniques

Similar to [Arrays](/data-structures/arrays.md)with some additions:

1. Think about using two pointers more
2. Count the frequency of characters using a fingerprint frequency array over a hash table if input character set is fixed size
3. Bitmasking to find duplicates
4. Anagram checking using frequency over sorting
5. Palindrome checking using converging two pointers
6. Counting the number of palindromes using two pointers diverging from middle


---

# 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://interviews.woojiahao.com/data-structures/strings.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.
