TopCoder problem "PaternityTest" used in SRM 155 (Division I Level One , Division II Level Three)



Problem Statement

    

DNA testing is one of the most popular methods of establishing paternity. In such a test, you compare samples of DNA from the man, the child, and the child's mother. For the purposes of this problem, assume that each sample is represented as a String of uppercase letters ('A'-'Z'). If half of the characters in the child's sample match the characters in the corresponding positions in the man's sample, and the remaining characters in the child's sample match the characters in the corresponding positions in the mother's sample, then the man is most likely the father. On the other hand, if it is impossible to partition the child's sample such that half of the characters match the man's and the other half match the mother's, then the man is definitely ruled out as the father.

For example, suppose the child's sample is "ABCD" and the mother's sample is "AXCY" (all quotes for clarity only). The 'A' and 'C' in the child's sample must have come from the mother, so the 'B' and 'D' must have come from the father. If the man's sample is "SBTD", then he is most likely the father, but if the man's sample is "QRCD", then he is definitely not the father. Note in the latter case that the man was definitely ruled out even though half of his sample (the 'C' and 'D') did in fact match the child's.

Your method will take samples from the child and the mother, as well as samples from several men, and return the indices of the men who cannot be ruled out as the father, in increasing order.

 

Definition

    
Class:PaternityTest
Method:possibleFathers
Parameters:String, String, String[]
Returns:int[]
Method signature:int[] possibleFathers(String child, String mother, String[] men)
(be sure your method is public)
    
 

Notes

-You may assume that the identity of the mother is not in question.
 

Constraints

-men contains between 1 and 5 elements, inclusive.
-child, mother, and all elements of men contain the same number of characters, which is even and between 2 and 20, inclusive.
-child, mother, and all elements of men contain only uppercase letters ('A'-'Z').
-At least half of the characters in mother match the characters in the corresponding positions in child.
 

Examples

0)
    
"ABCD"
"AXCY"
{ "SBTD", "QRCD" }
Returns: { 0 }
The example above.
1)
    
"ABCD"
"ABCX"
{ "ABCY", "ASTD", "QBCD" } 
Returns: { 1,  2 }
"ABCY" could not be the father. "ASTD" could be the father, with the 'A' and 'D' coming from the father and the 'B' and 'C' coming from the mother. "QBCD" could also be the father, with either the 'B' and 'D' or the 'C' and 'D' coming from the father.
2)
    
"ABABAB"
"ABABAB"
{ "ABABAB", "ABABCC", "ABCCDD", "CCDDEE" }
Returns: { 0,  1 }
3)
    
"YZGLSYQT"
"YUQRWYQT"
{"YZQLDPWT", "BZELSWQM", "OZGPSFKT", "GZTKFYQT", "WQJLSMQT"}
Returns: { }
4)
    
"WXETPYCHUWSQEMKKYNVP"
"AXQTUQVAUOSQEEKCYNVP"
{ "WNELPYCHXWXPCMNKDDXD",
  "WFEEPYCHFWDNPMKKALIW",
  "WSEFPYCHEWEFGMPKIQCK",
  "WAEXPYCHAWEQXMSKYARN",
  "WKEXPYCHYWLLFMGKKFBB" }
Returns: { 1,  3 }

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=4580&pm=1669

Writer:

vorthys

Testers:

lbackstrom , brett1479

Problem categories:

Brute Force