I\'m trying to get a head start on practicing interview questions and I came across this one:
Turn String aaaabbbbffffd into a4b4d3
You would basically want t
Here is the code that I tried.
I think you can't ask for a simpler code than this.
String s = "aaaabbbbffffd", modified = "";
int len = s.length(), i = 0, j = i + 1, count = 1;
char[] c = s.toCharArray();
for (; i < len; i = j) {
count = 1;
for (; j < len; j++)
if (c[i] == c[j])
count++;
else {
j++;
break;
}
modified += c[i] + "" + count;
}
System.out.println(modified);