Repeated DNA Sequences

Try to solve the Repeated DNA Sequences problem.

Statement

Given a string, dna, that represents a DNA subsequence, and a number kk, return all the contiguous subsequences (substrings) of length kk that occur more than once in the string. The order of the returned subsequences does not matter. If no repeated substring is found, the function should return an empty set.

The DNA sequence is composed of a series of nucleotides abbreviated as AA, CC, GG, and TT. For example, ACGAATTCCGACGAATTCCG is a DNA sequence. When studying DNA, it is useful to identify repeated sequences in it.

Constraints:

  • 11 ≤\leq dna.length ≤\leq 10410^4
  • dna[i] is either A, C, G, or T.
  • 1≤k≤101 \leq k \leq 10

Examples

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy