Frage im Vorstellungsgespräch bei Ticketfly

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