my testcase 2 and 3 shows wrong answer.please tell me what is wrong in the following code.
Doubt in "string compression"
hi rahul
check your code for following input
aaaaaaaaaaaaaaagggxsxssyyyyyoooooooooolllllwwqwdeddddddddkjjjoooooooooooooooooooo
expected output:
a15g3x1s1x1s2y5o10l5w2q1w1d1e1d8k1j3o20
your output:
a15d9e1g3j3k1l5o30q1s3w3x2y5
I do not understand how to get that output .please help me .
I write this but it show run time error.
i think your logic is not correct.
try thinking in this way.
- If all characters in the source string are different,
then size of destination string would be twice of input string.
For example if the src is “abcd”, then dest would be “a1b1c1d1”
For other inputs, size would be less than twice. - traverse the input string one by one
3)Copy the first occurrence of the new character
4)Count the number of occurrences of the new character
5)Store rLen in a character array count[] - Copy the count[] to destination
7)terminate the destination string
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.