At Slack, message data is sometimes stored as a mutable character buffer. Given a list of characters chars, compress it in place by replacing each group of consecutive repeated characters with the character followed by the group length if the length is greater than 1.
Return the new length of the compressed buffer. The first k positions of chars must contain the compressed result, where k is the returned length.
chars — a list of lowercase letters, uppercase letters, digits, or symbolsk representing the length of the compressed array after in-place modification1, write each digit of the count separatelyExample 1
chars = ["a","a","b","b","c","c","c"]6["a","2","b","2","c","3"]Example 2
chars = ["a"]1["a"]Example 3
chars = ["a","b","b","b","b","b","b","b","b","b","b","b","b"]4["a","b","1","2"]1 <= len(chars) <= 2000chars[i] is a single printable character