String Compression Testcases failure

Some testcases show wrong answer. The code first counts the number of distinct letters and then creates array of that size. It then calculates the first index of each distinct letter and then prints the compressed string.
Link : https://ide.codingblocks.com/s/198942

Hello @Chirag-Jain-1414278322030453,

Your logic will fail for the cases like:
abbbaacc
Expected Output:
a1b3a2c2

Hope, this would help.
Give a like if you are satisfied.

The code is working fine for abbbaacc

Hello @Chirag-Jain-1414278322030453,

It’s not working correctly.
Let me give you a better exmple:

  1. abb
    Expected Output:
    a1b2
    Your Output:
    a1b1
  2. aabbbc
    Expected Output:
    a2b3c1
    Your out[ut:
    a2b3c3
  3. aaaaaa
    Expected Output:
    a6
    Your Output:
    a0

Problrm:
You code is not computing the count of last character.
Rather it prints the count of previous character.

Hope, this would help.
Give a like if you are satisfied.

1 Like