I honestly thought this was going to be difficult to solve but after thinking about it for 30 minutes(writing out the pseudo-code) and letting diffused mode of thinking take its course, to my utter amazement, I solved this in 15 minutes(yep, I timed it).

I will just quickly write out my pseudo-code exactly the way I wrote it down in my book. I’m doing this because I want to show you that your pseudo-code might not be perfect or make much sense but the mere act of writing your logical thoughts on paper goes a long way.

This is exactly what is in my notes;


Take each character, get its pair and return the results in a 2D array.

Base pairs -> AT & CG => [[A, T], [C,G]]

String.prototype.split(), Array.prototype.push()


  1. Split the string into an array => [‘A’,’T’,’C’,’G’,’A’]
  2. Loop through the array to get each ‘character’
  3. Check a character to see if it exists in the base pairs[0](Loop through the base pairs)
  4. If its 0, add 1 and get the pair; if its 1, substract 1 and get its pair (indexOf)
  5. Create an array(partArr), add the character and the base pair; push the array into the bigger array (completeArr) and clear it OR create a string and split it while pushing into the bigger array (this was the method I used).

Thats all. Its not so elegant but it helped me to construct my thoughts on paper and allowed me to solve the problem in record time (record time for me, LOL).

Here is the link to the full code.

Thanks and happy coding 😀