Domanda di colloquio di Ticketfly

Given string write code that generate the output aaaabbb -> b aaabbbcccdd -> abc abc -> abc aabbbccdda -> ba