Take chars = ["a","b","b","b","b","b","b","b","b","b","b","b","b","c","c"]. The read pointer finds groups: "a" (count ), "b" (count ), "c" (count ).
The write pointer places "a" at index (no count since the group is ). Then it writes "b" at index , "1" at index , "2" at index . Then "c" at index and "2" at index . The result is ["a","b","1","2","c","2"] and you return .
Time: . Each character is read once and written at most once. Space: . You only use the two pointer variables and a counter.