DNA Max Write code to find which of the strands representing DNA in an array String[] strands representing strands of DNA has the most occurrences of the nucleotide represented by parameter nuc. Complete the definition of the class DnaMax and method definition maxStrand shown below. If more than one strand has the same maximal number of the specified nucleotide you should return the longest strand with the maximal number. All DNA strands have different lengths in this problem so the maximal strand will be unique when length is accounted for. Return this uniquely maximal strand. Each String representing a DNA strand will contain only cytosine, guanine, thymine, and adenine, represented by the characters 'c', 'g', 't', and 'a', respectively. If no strand in the array contains the specified nucleotide return the empty string "". public class DnaMax { public String maxStrand(String[] strands, String nuc) { // fill in code here } } Constraints strands will contain no more than 50 elements, each element will be a different length and the characters of the the strings will only be 'a', 'g', 't', or 'c'. nuc will be a one character string, either "a", "g", "t", or "c". Example 1 strands = {"agt", "aagt", "taattt", "ccatg" } nuc = "a" Returns "taattt" since both "aagt" and "taattt" have two occurrences of 'a', but "taattt" is longer. Example 2 strands = {"agt", "aagt", "taattt", "ccatc" } nuc = "g" Returns "aagt" since both "aagt" and "agt" have one occurrence of 'g', but "aagt" is longer. Example 3 strands = {"g", "gg", "ggg", "gggg"} nuc = "c" Returns "" because the nucleotide "c" doesn't occur in any strand.
DNA Max
Write code to find which of the strands representing DNA in an array String[] strands representing strands of DNA has the most occurrences of the nucleotide represented by parameter nuc. Complete the definition of the class DnaMax and method definition maxStrand shown below.
If more than one strand has the same maximal number of the specified nucleotide you should return the longest strand with the maximal number. All DNA strands have different lengths in this problem so the maximal strand will be unique when length is accounted for. Return this uniquely maximal strand.
Each String representing a DNA strand will contain only cytosine, guanine, thymine, and adenine, represented by the characters 'c', 'g', 't', and 'a', respectively. If no strand in the array contains the specified nucleotide return the empty string "".
public class DnaMax { public String maxStrand(String[] strands, String nuc) { // fill in code here } }
Constraints
- strands will contain no more than 50 elements, each element will be a different length and the characters of the the strings will only be 'a', 'g', 't', or 'c'.
- nuc will be a one character string, either "a", "g", "t", or "c".
Example 1
strands = {"agt", "aagt", "taattt", "ccatg" } nuc = "a"
Returns "taattt" since both "aagt" and "taattt" have two occurrences of 'a', but "taattt" is longer.
Example 2
strands = {"agt", "aagt", "taattt", "ccatc" } nuc = "g"
Returns "aagt" since both "aagt" and "agt" have one occurrence of 'g', but "aagt" is longer.
Example 3
strands = {"g", "gg", "ggg", "gggg"} nuc = "c"
Returns "" because the nucleotide "c" doesn't occur in any strand.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images