<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 {
public:
    int d = 26;
    int prime = 101;
    int computeHash(const string &s, int length) {
		long long hash = 0;
	    long long multiplier = 1;
	    for(int i = length-1; i >= 0; i--) {
		    hash =(hash + (s[i]- 'A' +1) * multiplier);
            // cout<<s[i]<<" "<<hash<<endl;
          
		    multiplier = (multiplier*d)%prime;
	    }
	    return hash%prime;
    }

    vector<string> findRepeatedDnaSequences(string s) {
        // AAAAACCCCC
        // AAAAACCCCC
        vector<string>ans;
        if(s.length() < 11) {
            return ans;
        }
        // CAAAAAAAAAC
        // CAAAAAAAAA
	    long long hash = computeHash(s.substr(0,10), 10);
        cout<<endl;
        cout<<"hash1: "<<hash<<endl;
        int hash2 = computeHash(s.substr(1, 10), 10);
        cout<<"hash2: "<<hash2<<endl;
	    string substr = s.substr(0, 10);
	    map<int,map<string, int>>mp;
        // cout<<"here"<<endl;
	    for(int j = 0; j <= s.length()-10; j++) {
            //  mp[hash].find(substr) != mp[hash].end() && mp[hash][substr] < 2
		    if(mp.find(hash) != mp.end() && mp[hash].find(substr) != mp[hash].end() && mp[hash][substr] < 2) {
			    ans.push_back(substr);
                mp[hash][substr]++;
		    } else {
                // cout<<"putting it in map";
                mp[hash][substr]++;
		    };
            long long k = pow(d, 9);
            // cout<<"big: "<<k<<endl;
            
		    if(j < s.length()-10) {
                // hash = (((hash-((s[j]- 'A' +1)* k))* d)+(s[j+10]- 'A' +1))%prime;
                // hash = (( hash - ((s[j] - 'A' + 1) *k ) %prime ) * d + (s[j+10] - 'A' + 1) )%prime;
                hash = (((hash - ((s[j]-'A' + 1) * k)) * d)+ (s[j+10]- 'A' +1))%prime;
                if(hash < prime) {
                    hash += prime;
                }
            }
            
            substr = s.substr(j+1, 10);
		    
            cout<<hash<<endl;
	    }
        // cout<<"end";
	    return ans;

    }
};
26390