> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Repeated DNA Sequences Python Solution

> Tested Python solution for LeetCode 187 with 17 pytest cases. Generate a practice environment with lcpy.

LeetCode 187, [Medium](/catalog/medium). Topics: [Hash Table](/catalog/topics/hash-table), [String](/catalog/topics/string), [Bit Manipulation](/catalog/topics/bit-manipulation), [Sliding Window](/catalog/topics/sliding-window), Rolling Hash, [Hash Function](/catalog/topics/hash-function). [View on LeetCode](https://leetcode.com/problems/repeated-dna-sequences/description/).

Generate this problem as a practice environment: tested reference solution, 17 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 187   # by problem number
lcpy gen -s repeated_dna_sequences   # by problem name
```

## Problem

The **DNA sequence** is composed of a series of nucleotides abbreviated as `'A'`, `'C'`, `'G'`, and `'T'`.

* For example, `"ACGAATTCCG"` is a **DNA sequence**.

When studying **DNA**, it is useful to identify repeated sequences within the DNA.

Given a string `s` that represents a DNA sequence, return all the **10-letter-long sequences** (substrings) that occur more than once in a DNA molecule. You may return the answer in **any order**.

### Examples

```
Input: s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT"
Output: ["AAAAACCCCC","CCCCCAAAAA"]
```

```
Input: s = "AAAAAAAAAAAAA"
Output: ["AAAAAAAAAA"]
```

### Constraints

* 1 \<= s.length \<= 10\<sup>5\</sup>
* `s[i]` is either `'A'`, `'C'`, `'G'`, or `'T'`.

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/repeated_dna_sequences/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/repeated_dna_sequences/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(n * L) where L is the sequence length (10)
    # Space: O(n * L)
    def repeated_dna_sequences(self, s: str) -> list[str]:
        seen: set[str] = set()
        repeated: set[str] = set()
        for i in range(len(s) - 9):
            sequence = s[i : i + 10]
            if sequence in seen:
                repeated.add(sequence)
            seen.add(sequence)
        return list(repeated)
```

## Complexity

| Time | Space |
| - | - |
| O(n \* L) where L is the sequence length (10) | O(n \* L) |

## Tags

[NeetCode All](/catalog/neetcode).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.