Sir , i am not able to understand your logic of solving string compression probel

#include <bits/stdc++.h>
using namespace std;

string compress(string s)
{
if (s.size() == 0)
{
return “”;
}

char ch = s[0];
int i = 1;
while (i < s.size() && s[i] == ch)
{
    i++;
}

string ros = s.substr(i);
ros = compress(ros);

string charCount = to_string(i);
return ch + charCount + ros;

}

int main()
{
string s;
cin >> s;

cout << compress(s) << endl;

return 0;

}
please explain .

my code is
#include
#include
#include
using namespace std;
int main()
{
string s;
getline(cin,s);
int l=s.length();
int sum=1;
for(int i=0,j=1;i<l,j<=l;i++,j++)
{
if(s[i]==s[j])
{
sum++;
}
else if(s[i]!=s[j])
{
cout<<s[i];
cout<<sum;
sum=1;
}
else
{
cout<<s[i];
cout<<sum;
}
}
return 0;
}

In this question you need to tell how many times a character appears in local clusters for example in aaabbbaaa answer would be a3b3a3, the logic is pretty simple j points to i+1, and if s[i] == s[j] we increment the counter and if s[i] != s[j] we know that the cluster has ended we print the character (s[i]) and its count.

Sir, I know the logic but I am. Notable to understand the code of your editorial.

again the code is very simple as explained above, it takes i and j where j points towards i+1, s[i] == s[j] we increment the counter and if s[i] != s[j] we know that the cluster has ended we print the character (s[i]) and its count.

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.