Please tell why my code is not running for test case 2 and 3

#include
#include
using namespace std;
void max_char(string s)
{
int n = s.length();
int arr[26] ={0};
int d = 0;
int max = 0;
for(int i = 0 ; i < n ; i++)
{
int c = s[i];
arr[c - 97]++;
}
for(int i = 0 ; i < 26 ; i++)
{
if(arr[i] > 0)
{
d = arr[i];
cout<<char(97 + i)<<d;
}
}

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

@dhruvtrehan45
you are counting the total frequency of a character but here you need to take its frequency till its repeating consecutively.
Look at these examples it will make it clear:-
eg1 :- aabbaa -> a2b2a2
eg2:- abbab -> a1b2a1b1