Codechef•Jun 09, 2025
Complementary Strand in a DNA
Hazrat Ali
Codechef
You are given the sequence of Nucleotides of one strand of DNA through a string SS of length NN. SS contains the character A,T,C,A,T,C, and GG only.
Chef knows that:
- AA is complementary to TT.
- TT is complementary to AA.
- CC is complementary to GG.
- GG is complementary to CC.
Using the string SS, determine the sequence of the complementary strand of the DNA.
Input Format
- First line will contain TT, number of test cases. Then the test cases follow.
- First line of each test case contains an integer NN - denoting the length of string SS.
- Second line contains NN characters denoting the string SS.
Output Format
For each test case, output the string containing NN characters - sequence of nucleotides of the complementary strand.
Constraints
- 1≤T≤100
- 1≤N≤100
- SS contains
A
,T
,C
, andG
only
Sample 1:
Input
4 4 ATCG 4 GTCC 5 AAAAA 3 TAC
Output
TAGC CAGG TTTTT ATG
Solution
t = int(input())
for _ in range(t):
n = int(input())
strand = input()
complement = ''
for ch in strand:
if ch == 'A':
complement += 'T'
elif ch == 'T':
complement += 'A'
elif ch == 'C':
complement += 'G'
else: # ch == 'G'
complement += 'C'
print(complement)