Feature #8: Compress File II

Implement the "Compress File II" feature for our "Operating System" project.

Description

The ability to compress files is an essential functionality that can come in handy. In this feature, we will learn how to carry out basic file compression, just like the one that WinZip does. The file compression process will compress text files by replacing multiple consecutive occurrences of the same character with that character followed by the number of its consecutive occurrences. If a character does not have any consecutive repetitions, then we will just write the character to the output. For example, "abbbbccc" will become "ab4c3". Our task will be to return the compressed file using constant additional space.

Note: Suppose that 'a' repeats 15 times. In that case, we will compress it like this: ['a', '1', '5']

We will be provided with a character list that will represent the text in a file.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.