Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string compression solutions don't match description #271

Open
cristianmtr opened this issue Jun 8, 2020 · 2 comments
Open

string compression solutions don't match description #271

cristianmtr opened this issue Jun 8, 2020 · 2 comments

Comments

@cristianmtr
Copy link

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 ?

@amitShindeGit
Copy link

What could we do here then to save space?
I'd really like to know.

@adarsh-tyagi
Copy link

adarsh-tyagi commented Mar 10, 2021

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)
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants