Implement a string compressor
Write a function that takes a string and returns a compressed version, where consecutive duplicate characters are replaced with a single character followed by the number of repetitions.
For example, “aabccc” becomes “a2bc3”.
- Fill in the code.
- You can copy the code into IntelliJ/Android Studio, but it shouldn’t be necessary.
- Click “run” – the green triangle. The code will compile and several tests will be run.
- In the logs, you will see “try again” if the solution is incorrect, or “success” and a special code.
- Provide this code in the form below along with your email and click “send”.
- Solutions will be presented the next day on Instagram
test cases
fun test1() = compressString("aabccc") == "a2bc3" fun test2() = compressString("abcd") == "abcd" fun test3() = compressString("aaabaaa") == "a3ba3" fun test4() = compressString("") == "" fun test5() = compressString("bbbbb") == "b5"