String- string compression

Not able to test case 2(rest passed).

#include
#include
using namespace std;
int main() {

char arr[1000];
int ar[100];
cin.getline(arr,1000);
for(int i=0;i<strlen(arr);i++){
int j=i;
int count=0;
while(j<strlen(arr)){	
	if(arr[i]==arr[j]){
		count++;
		
	}
	j++;
}
ar[i]=count;
}
for(int i=0;i<strlen(arr);i=i+ar[i]){
	if(ar[i]!=1){
		cout<<arr[i]<<ar[i];
	}
	else{
		cout<<arr[i];
	}
}
return 0;

}

@shuja33,
for aaabbaaa your output is a6a2 but ans should be a3b2a3

@shuja33, you can refer to https://ide.codingblocks.com/s/655945

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.