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 10310^3
  • dna[i] is either A, C, G, or T.
  • 1k101 \leq k \leq 10

Examples

Press + to interact
canvasAnimation-image
1 of 2

Understand the problem

Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:

Repeated DNA Sequences

1

(Select all that apply.) What is the output if the following string and value of kk are given as input?

dna = “AGCTGAAAGCTTAGCTG”

k = 5

A)

AGCTG

B)

TTAGC

C)

AAGCT

D)

AAAGC

Question 1 of 30 attempted

Figure it out!

We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.

Drag and drop the cards to rearrange them in the correct sequence.

Try it yourself

Implement your solution in the following coding playground:

Press + to interact
JavaScript
usercode > main.js
function findRepeatedSequences(dna, k) {
// Replace this placeholder return statement with your code
return new Set();
}
export { findRepeatedSequences };
Repeated DNA Sequences