HSBC Interview Question

count repeated characters and replace these characters in a string