In a deep space mission, transmissions are encoded for efficiency. Given a string of 97 to 6787 characters consisting of lowercase English letters representing signal patterns, write a function to compress it using a custom encoding where sequences of the same letters are replaced by the letter followed by the count of its consecutive occurrences, except when the count is 1, in which case only the letter is output, and sequences of exactly two identical letters are left uncompressed.
Explanation: The sequence 'aa' is left as is because it has exactly two characters, 'bbb' is compressed to '3b', and 'cccccc' is compressed to '6c'.
Explanation: Each character appears only once, so no compression is applied.
Explanation: The sequence of ten 'a's is compressed to 'a10'.
Master coding challenges related to Strings and solve the [Backup] Galactic Transmission Encoding problem optimally.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak