<p>The <strong>DNA sequence</strong> is composed of a series of nucleotides abbreviated as <code>&#39;A&#39;</code>, <code>&#39;C&#39;</code>, <code>&#39;G&#39;</code>, and <code>&#39;T&#39;</code>.</p>

<ul>
	<li>For example, <code>&quot;ACGAATTCCG&quot;</code> is a <strong>DNA sequence</strong>.</li>
</ul>

<p>When studying <strong>DNA</strong>, it is useful to identify repeated sequences within the DNA.</p>

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

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT"
<strong>Output:</strong> ["AAAAACCCCC","CCCCCAAAAA"]
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> s = "AAAAAAAAAAAAA"
<strong>Output:</strong> ["AAAAAAAAAA"]
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
	<li><code>s[i]</code> is either <code>&#39;A&#39;</code>, <code>&#39;C&#39;</code>, <code>&#39;G&#39;</code>, or <code>&#39;T&#39;</code>.</li>
</ul>

from collections import defaultdict
class Solution:
    def encode(self, ch):
        if ch == 'A':
            return 0
        if ch == 'C':
            return 1
        if ch == 'G':
            return 2
        return 3

    def decode(self, num):
        if num == 0:
            return 'A'
        if num == 1:
            return 'C'
        if num == 2:
            return 'G'
        return 'T'
    
    def decodeSeq(self, encSeq):
        seq = ""
        for i in range(10):
            seq = self.decode(encSeq % 4) + seq
            encSeq >>= 2
        return seq

    def convertSeq(self, seq):
        enc = 0
        i = 18
        for s in seq:
            enc |= (self.encode(s) << i)
            i -= 2
        return enc
    
    def addToSeq(self, seq, ch):
        return (((1<<20)-1) & (seq << 2)) | self.encode(ch)

    def findRepeatedDnaSequences(self, s: str) -> List[str]:
        encMap = defaultdict(int)
        seq = self.convertSeq(s[:10])
        encMap[seq] += 1
        repeated = set()

        for i in range(10, len(s)):
            seq = self.addToSeq(seq, s[i])
            if encMap[seq] > 0:
                repeated.add(seq)
            encMap[seq] += 1

        return [self.decodeSeq(encSeq) for encSeq in repeated]
            
27600