You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Hello
In the string compression challenge:
Only compress the string if it saves space.
The
C2
doesn't save space, right? Shouldn't it be justCC
?The text was updated successfully, but these errors were encountered: