Consider an array of characters chars. You need to compress it in-place using the following rule: for each group of consecutive repeating characters, write the character followed by the group's length (only if the length is greater than ). Return the new length of the array after compression. Amazon asks in-place array problems to evaluate your two-pointer efficiency.
For example, ["a","a","b","b","c","c","c"] becomes ["a","2","b","2","c","3"], and you return .
The catch: you must do this in-place with only constant extra space. Think about how you'd read groups from the array while simultaneously writing the compressed result back into it.