Compress a string such that 'AAABCCDDDD' becomes 'A3BC2D4'. Only compress the string if it saves space.
- Can we assume the string is ASCII?
- Yes
- Note: Unicode strings could require special handling depending on your language
- Is this case sensitive?
- Yes
- Can we use additional data structures?
- Yes
- Can we assume this fits in memory?
- Yes
Instructions:
-
Program should be written in file build.py
-
Function name should be compress.
-
Input
Type: String Value: 'AABBBCDDEEEE'
-
Expected Output
Type: String Value: 'A2B3CD2E4'