Try to solve the Repeated DNA Sequences problem.
We'll cover the following
Statement
Given a string, dna
, that represents a DNA subsequence, and a number , return all the contiguous subsequences (substrings) of length 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 , , , and . For example, is a DNA sequence. When studying DNA, it is useful to identify repeated sequences in it.
Constraints:
-
dna.length
dna[i]
is either A, C, G, or T.
Examples
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
(Select all that apply.) What is the output if the following string and value of are given as input?
dna = “AGCTGAAAGCTTAGCTG”
k = 5
AGCTG
TTAGC
AAGCT
AAAGC
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.
Try it yourself
Implement your solution in the following coding playground:
function findRepeatedSequences(dna, k) {// Replace this placeholder return statement with your codereturn new Set();}export { findRepeatedSequences };