DEV Community

Discussion on: String Compression. Facebook interview question.

Collapse
 
elasticrash profile image
Stefanos Kouroupis

Even if this is not a true compression, the word compression though implies less characters (or the same) so you could make an assumption that for characters repeated less than 3 times there is no need to compress them. so

  • asdf will stay asdf
  • aasdff will stay aasdff
  • aasssdfff will become aas3df3

and when compressing numbers you could use a token approach

Collapse
 
akhilpokle profile image
Akhil

Yep, we could compare if the "compressed" version is indeed shorter and if it's shorter then use that one.