• Another test case to add "aaaaaa1234567890123Ubefg".
My solution was accepted but got wrong answer for this test case.

``````  public class Solution {
int lower = 0;
int upper = 0;
int digits = 0;
int count = 1;
int change = 0;
int r1=0;
int r2=0;

for(int i=0;i<s.length();i++){
if(s.charAt(i)>='A' && s.charAt(i) <= 'Z')  {
upper++;
} else if(s.charAt(i)>='a' && s.charAt(i) <='z') {
lower++;
} else if(s.charAt(i)>='0' && s.charAt(i) <= '9') {
digits++;
}
if(i+1<s.length() && s.charAt(i)==s.charAt(i+1)){
count++;
}else{
if(count>=3){
if (count %3 ==0){
r1++;
}else if (count %3 ==1){
r2++;
}
change += count/3;
}
count = 1;
}
}

int delete = 0;
if(s.length()>20)
delete = s.length()-20;

System.out.println(change+" "+r1+" "+r2);
int tmp=delete;
// 1:1 replace "change" with "delete"
if(tmp>0){
change-=Math.min(r1, tmp);
tmp=Math.max(0, tmp-r1);
}
// 1:2 replace "change" with "delete"
if(tmp>0){
change-=Math.min(r2, tmp/2);
tmp=Math.max(0, tmp-r2*2);
}
// 1:3 replace "change" with "delete"
/*if(tmp>0){
change-=Math.min(change, tmp/3);
tmp=Math.max(0, tmp-change*3);
}*/
// 1:1 replace "change" with "add"