<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>

class Solution:
    def findRepeatedDnaSequences(self, s: str) -> List[str]:
        L = 10
        a = 4
        aL = pow(a,L)
        n = len(s)
        if n<=L:
            return []
        res = set()
        seen = set()
        to_int = {'A':0, 'C':1, 'G':2, "T":3}

        nums = [to_int.get(j) for j in s]
        h = 0
        for start in range(n-L+1):
            if start==0:
                for i in range(L):
                    h = h*a + nums[i]
            else:
                h = h*a - nums[start-1]*aL + nums[start+L-1]
            if h in seen:
                res.add(s[start:start+L])
            seen.add(h)
        return res

        
        
        
        
        
        # sequence_count = {}
        # res = []

        # for i in range(len(s) - 9):  # Sliding window of length 10
        #     seq = s[i:i+10]
        #     if seq in sequence_count:
        #         sequence_count[seq] += 1
        #     else:
        #         sequence_count[seq] = 1

        #     if sequence_count[seq] == 2:  # Add to result if it's seen twice
        #         res.append(seq)

        # return res
       
       
       
        # seen = {}
        # res = []
        # for i in range(len(s)-9):
        #     seq = s[i:i+10]
        #     seen[seq] = seen.get(seq,0)+1
        #     if seen[seq]==2:
        #         res.append(seq)
        # return res
        
            
26900