Solution for the LZW compression algorithm