The base problem wasn't too bad once I realized I needed two pointers, one for reading and one for writing.
Use a two-pointer technique: one pointer reads the array to identify runs, and another writes the compressed characters in place. For each run, write the character, then if the count is greater than 1, write each digit of the count as a separate character. Return the write pointer as the new length.
Pro tip: Clarify that the input array is mutable and that we can overwrite characters we've already read, since the write pointer never exceeds the read pointer. Also, handle edge cases like empty array and runs longer than 9 by writing multiple digits.
Restate the problem: compress the array in place using run-length encoding, skipping count for single characters, and return the new length. Emphasize O(1) extra space, so we must modify the array directly.
Use a read pointer to scan runs and a write pointer to overwrite the array. For each run, write the character and then the count digits if count > 1.
Convert the count to individual digit characters (e.g., 12 becomes '1' and '2'). Consider edge cases: empty array, single character, runs of length 1, and runs longer than 9.
Walk through a concrete example like ['a','a','b','b','c','c','c'] to show the in-place modification and verify the returned length. Discuss time and space complexity: O(n) time, O(1) space.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.