Pergunta de entrevista da empresa Birlasoft

Write a function to compress a string using run-length encoding. For example, for input "aaabbbccc", the output should be "a3b3c3".