<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:
    vector<string> findRepeatedDnaSequences(string s) {
        //sliding window
        //cache each window

        //get a size 10 window
        //check if the window has been cached
        //if it has
            //add this to a return set
        //otherwise cache it
        
        //slide the window up
        //take all the values from the return set and add it to a return vector

        std::unordered_set<string> return_set;
        std::unordered_set<string> duplicate_set;
        //edge case if there is a dna sequence that is less than 10 long
        if(s.size() < 10){
            return {};
        }
        // int pointer = 0;
        const int length = 10;
        for(int i = 0; i < s.size() - length + 1; i++){
            string dna_sequence = s.substr(i, length);
            if(duplicate_set.find(dna_sequence) != duplicate_set.end()){
                //exists already
                return_set.insert(dna_sequence);
            }
            else{
                duplicate_set.insert(dna_sequence);
            }

        }
        std::vector<string> return_vector;
        for(auto dna : return_set){
            return_vector.push_back(dna);
        }
        return return_vector;
    }
};
21071