← AlgoMindset 75

String Compression

Medium🎙 Interview me on this

🧠 Before you code — what pattern fits?

Given an array of characters chars, compress it in place: consecutive repeating characters become the character followed by the group length (if greater than 1; lengths of 10 or more are split into separate digit characters).

Return the new length of the array. For this judge, return the compressed prefix as its length (the array is checked up to that length).

["a","a","b","b","c","c","c"] → 6, array becomes ["a","2","b","2","c","3"]

🎬 Video explanation · Apna College

Your solution runs against 3 unit tests, including edge and large-value cases.

Loading...

Test console · 3 unit tests

Submit your code to run it against all 3 unit tests. Results appear here.

JavaScript, TypeScript & Python run sandboxed in your browser; other languages run on the execution server. Your code is saved locally as you type.