Run-length encoding

This Question Was Asked By Amazon

Run-length encoding is a fast and simple method of encoding strings. The basic idea is to represent repeated successive characters as a single count and character.
Implement run-length encoding and decoding. You can assume the string to be encoded have no digits and consists solely of alphabetic characters. You can assume the string to be decoded is valid.

Write a function encode which accepts the following parameter:
1.) a = a string

And returns an encoded representation of the string.

Write a function decode which accepts the following parameter:
1.) a = a string

And returns valid if the string is correctly encoded.

Example
encode(AAAABBBCCDAA)`` The function should return, 4A3B2C1D2A`

Input:
decode(4A3B2C1D2A)
The function should return,
AAAABBBCCDAA

Constraints
• The length of a string should be greater than 0 and less than 100.