String Compression Problem
Given a string, write a function to compress it by shortening every sequence of the same character to that character followed by the number of repetitions. If the compressed string is longer than the original, you should return the original string.
Function Description
Complete the function compressString in the editor.
compressString has the following parameter:
String input: the string to compress
Returns
String: the compressed string or the original string if the compressed one is longer
Example
Unlock to view complete problem details
and practice with sample input/output
Was this article helpful?
View Test Cases & Run Code requires membership
Input Variables
Execution Result:
