string compression solutions don't match description
Hello
In the string compression challenge:
- you say
Only compress the string if it saves space. - but you have expected outputs like
assert_equal(func('AAABCCDDDDE'), 'A3BC2D4E')
assert_equal(func('BAAACCDDDD'), 'BA3C2D4')
assert_equal(func('AAABAACCDDDD'), 'A3BA2C2D4')
The C2 doesn't save space, right? Shouldn't it be just CC ?
What could we do here then to save space? I'd really like to know.
Alphabets count should be taken only when they are recurring more than 2 times. Let's say we have string AAABCCD, in this string A occurs thrice then it will be A3, B and D are single so they will be taken as it is. But in case of C, count should be taken if it is ocurring more than twice. In this case it should be CC but when it is more than 2 suppose CCC then the count should be taken. We can do this by below method.
` s = "AAABCCDDDDE" output = '' hashMap = {} for i in range(0, len(s)): if s[i] not in hashMap: hashMap[s[i]] = 1 else: hashMap[s[i]] += 1
for key, value in hashMap.items(): if value > 2: output += str(key)+str(value) else: output += str(key)*value
print(output) `