Un-de-duplicating strings
MATL, 7 bytes
Y'to+Y"
Try it online! Or verify all test cases.
Let's take 'ABBA'
as example input.
Y' % Implicit input. Run-length decoding
% STACK: 'ABA', [1 2 1]
t % Duplicate top of the stack
% STACK: 'ABA', [1 2 1], [1 2 1]
o % Modulo 2
% STACK: 'ABA', [1 2 1], [1 0 1]
+ % Add, element-wise
% STACK: 'ABA', [2 2 2]
Y" % Run-length encoding. Implicit display
% STACK: 'AABBAA'
Retina, 11 bytes
(.)\1?
$1$1
Try it online - contains all test cases
Perl, 16 bytes
15 bytes of code + -p
flag.
s/(.)\1?/$1$1/g
To run it:
perl -pe 's/(.)\1?/$1$1/g' <<< 'HEY'