Pergunta de entrevista da empresa HSBC

count repeated characters and replace these characters in a string