TopCoder problem "AnalyzeDNA" used in SRM 19 (Division I Level Three , Division II Level Three)



Problem Statement

    
Class name: AnalyzeDNA
Method name: findClosest
Parameters: String[]
Returns: int

Implement a class AnalyzeDNA which contains a method findClosest.  findClosest
takes a String[] as a parameter and returns an int indicating the least number
of "mutations" needed to turn any one String from the String[] into any other
different String from the String[] (in other words, return the minimum of the
minimums).

Valid "mutations" include:
*removing one letter from any position in the String. (i.e. AGACT -> AGCT)
*inserting one letter at any position in the String. (i.e. AGACT -> ATGACT)
*changing any one letter at any position in the String. (i.e. AGACT -> ATACT)

Duplicate Strings in the String[] are not considered to be different.  For
example, if the String "ATGC" appears in the String[] twice, the second
occurrence should be ignored.  Also, if no combination of "mutations" can turn
one String from the String[] into another different String, the method should
return -1.  Therefore, for a String[] containing no Strings, one String, or all
duplicates of the same String, the method should return -1.

The method signature is:
int findClosest (String[] collection);
Be sure your method is public.

*collection must contain no more than 10 Strings.
*All Strings in collection are no longer than 15 letters in length, no shorter
than 1 letter and can only contain the characters 'A', 'T', 'G', and 'C'.

Examples:

*collections = {"GTTCAGCACC", "GACTGATCCC"} requires 5 mutations as follows
(changing the first to the second):
GTTCAGCACC GACTGATCCC -> Remove 8th character ->
GTTCAGCCC GACTGATCCC -> Insert 'A' at 2nd position->
GATTCAGCCC GACTGATCCC -> Change 3rd position to 'C' ->
GACTCAGCCC GACTGATCCC -> Change 4th position to 'G' ->
GACTGAGCCC GACTGATCCC -> Change 6th position to 'T' ->
GACTGATCCC GACTGATCCC (done) and the method should return 5.
*If collection={"ATGC"}, then there is only one string, and the method should
return -1.
*If collection={"ATGCGCGTA","CGAGTGACG"}, then 7 mutations are required to
transform "ATGCGCGTA" into "CGAGTGACG", and the method should return 7.
*If collection={"TCAGGTCGCACTTTG","GGACCGGCGTATCTC"}, then 9 mutations are
required to transform "TCAGGTCGCACTTTG" into "GGACCGGCGTATCTC", and the method
should return 9.
*If
collection={"AAAAAAAAAAAAAAA","CCCCCCCCCCCCCCC","TTTTTTTTTTTTTTT","GGGGGGGGGGGGG
GG"} then 15 mutations are required to turn any String into any other and the
method should return 15.

 

Definition

    
Class:AnalyzeDNA
Method:findClosest
Parameters:String[]
Returns:int
Method signature:int findClosest(String[] param0)
(be sure your method is public)
    

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=130

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=3018&pm=130

Writer:

doeth

Testers:

Problem categories: