Yandex interview question

Write a string compression algorithm like RLE Input: AAABBBCDDDD Output: A4B3CD4