ComplementaryDNAChains
TCCC07 Qual 3 · 2007-07-30 · by ivan_metelsky
Problem Statement
A DNA chain is a sequence of proteins of 4 types. The types are encoded using the characters 'A', 'C', 'G', 'T'. Two proteins are called complementary if one is of type 'A' and the other is of type 'T', or if one is of type 'C' and the other is of type 'G'. Two DNA chains are called complementary if they have equal length, and the i-th protein in the first chain and the i-th protein in the second chain are complementary for all possible values of i.
You will be given
Constraints
- first will contain between 1 and 50 characters, inclusive.
- second will contain the same number of characters as first.
- Each character in first and second will be 'A', 'C', 'G' or 'T'.
"ACGT" "TGCA" Returns: 0
The input DNA chains are already complementary, so no replacements are needed.
"ACGT" "ACGT" Returns: 4
We need 4 replacements to transform one of the input DNA chains to "TGCA": ACGT -> TCGT -> TGGT -> TGCT -> TGCA.
"ATAGTACCAC" "CTTATTGGGT" Returns: 6
"GAGCACTTGACGTTCCTAACCTGCCCTCGCCAATATTCT" "CGCCCACCAATGATGGCTGCAATCCTTCATGCTTGTTTC" Returns: 30
"CCGTAAAGATTTGCCTTTATTCATA" "ATTCTTGTGACGCGAACGACCTTGA" Returns: 18
Submissions are judged against all 32 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ComplementaryDNAChains with a public method int minReplaces(string first, string second) · 32 test cases · 2 s / 256 MB per case