Find Repeated 10-Letter DNA Sequences

A DNA sequence is a string made up of the following four characters:

  • 'A'
  • 'C'
  • 'G'
  • 'T'

Given a string s representing a DNA sequence, find all substrings of length 10 that appear more than once in s.

Return all such repeated 10-letter-long substrings in any order.

Example 1:

Input: s = "TTTTTGGGGGTTTTTGGGGG"

Output: ["TTTTTGGGGG"]

Explanation:

The substring "TTTTTGGGGG" appears twice in the DNA sequence.

Example 2:

Input: s = "ACGTACGTACGTACGTACGT"

Output: ["ACGTACGTAC","CGTACGTACG","GTACGTACGT","TACGTACGTA"]

Explanation:

These 10-letter substrings occur more than once:

  • "ACGTACGTAC"
  • "CGTACGTACG"
  • "GTACGTACGT"
  • "TACGTACGTA"

Now Your Turn!

Pick the correct output for the given input

Input: s = "AAAAAAAAAAA"

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= s.length <= 105
  • s consists only of the characters 'A', 'C', 'G', and 'T'

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
vector<string> findRepeatedDnaSequences(string s) {
// Your code goes here
}
};
Test Case

Input:

S