HSBC interview question

count repeated characters and replace these characters in a string