APT: DNA Max

Problem Statement

You are writing code to find which of several scanned DNA strands has the most occurrences of a specific nucleotide. 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.

Definition

Class

public class DNAMaxNucleotide { public String max(String[] strands, String n) { // fill in code here } }

Notes

Constraints

Examples

  1.  strands = {"agt", "aagt", "taattt", "ccatg" }
     n = "a"
    
    
    Returns: "taattt" since both "aagt" and "taattt" have two occurrences of 'a', but "taattt" is longer.

  2.  strands = {"agt", "aagt", "taattt", "ccatc" }
     n = "g"
    
    
    Returns: "aagt" since both "aagt" and "agt" have one occurrence of 'g', but "aagt" is longer.


Owen L. Astrachan
Last modified: Mon Sep 24 10:07:34 EDT 2007