Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Use a read pointer to scan groups of consecutive identical characters and a write pointer to overwrite the array in-place. For each group, write the character followed by its count digits (only if count exceeds 1). Return the write pointer as the new length.
The write pointer never overtakes the read pointer because the compressed form is always shorter or equal. Writing char + count digits in-place is safe since we have already read past those positions.
Updated Feb 2026