DEV Community

Discussion on: String Compression. Facebook interview question.

Collapse
 
slax0rr profile image
Tomaz Lovrec • Edited

Using this, encoding a string like 'asdf' will produce a string that is twice the size, since 'asdf' will become, 'a1s1d1f1'.

Collapse
 
akhilpokle profile image
Akhil

Yep, it's efficient when a string contains multiple repeated characters but still, it won't guarantee the shortest string. Eg: is the string is Mississippi, compressed will be: m1i1s2i1s2i1p2i1 which is actually longer, even though some of the characters are repeating.

This question serves as a general idea towards why we go for compression, I will write about complex topics like Huffman coding in the future.