Rosalind - Complementing a Strand of DNA

rosalind

Problem:

Please find the problem here.

Solution:

This problem has an in-place solution. We can walk the string from two ways and swap and map at the same time. However, Python strings are immutable. We have to create new strings.

To build a string, I was thinking about something like a StringBuilder, but there is no such thing in Python. It is reported that doing repeated string concatenation is the fastest way. So I simply constructed the new string using repeated string concatenation.

Code: