how should i stop repetitive output in it
String compression
hey @lovely , solution for this problem can be in 2 different time complexity , that is in O(n) and O(n^2), what you are doing is O(n^2), but is not correct method for the same. You should do it using this approach
a) Pick the first character from the source string.
b) Append the picked character to the destination string.
c) Count the number of subsequent occurrences of the picked character and append the count to the destination string.
d) Pick the next character and repeat steps b) c) and d) if the end of the string is NOT reached.
Source code for the same is at
so this above code is for o(n) approach?
No, it’s O(N^2) as you can see two for loop. For O(N) approach you have to use hashing. When you will know about hashing in your course, then only use it. There’s no need of doing it right now.
yes thats why i didnt follow that approach .as i had not knowledge of hashing.
You can submit it as it is of O(N^2) and you also know it’s concept 
i cannot understand
else
i=j-1
break;
line .why we use that?
If we get Adjacent elements I.e., from I … j , then we increment j with count. Else we place I to j-1 and then break for loop of j
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.