Introduction
Let's observe the following string:
AABBCCDDEFFGG
You can see that every letter has been duplicated, except for the letter E
. That means that the letter E
has been de-duplicated. So, the only thing we need to do here is to reverse that process, which gives us the following un-de-duplicated string:
AABBCCDDEEFFGG
Let's take a harder example:
AAAABBBCCCCDD
You can see that there is an uneven number of consecutive B
's, so that means that one of the BB
was de-duplicated from the original string. We only need to un-de-duplicate this letter, which gives us:
AAAABBBBCCCCDD
The challenge
Given a non-empty de-duplicated string, consisting of only alphabetic characters (either only uppercase or only lowercase), return the un-de-duplicated string. You can assume that there will always be at least one de-duplicated character in the string.
Test cases
AAABBBCCCCDDDD --> AAAABBBBCCCCDDDD
HEY --> HHEEYY
AAAAAAA --> AAAAAAAA
N --> NN
OOQQO --> OOQQOO
ABBB --> AABBBB
ABBA --> AABBAA
This is code-golf, so the shortest valid submission in bytes wins!
AABBBB
. \$\endgroup\$ABBB
map toAABBBB
, notAABBBBBB
? \$\endgroup\$A BB B
. The characters that aren't paired (and therefore not duplicated) need to be duplicated, resulting inAA BB BB
, which is the un-de-duplicated string. \$\endgroup\$