Problem Category:: Array Neetcode Category:: Arrays and Hashing

https://leetcode.com/problems/encode-and-decode-strings/

Design an algorithm to encode a list of strings to a string. The encoded string is then sent over the network and is decoded back to the original list of strings

Method 1

Chunked transfer encoding

Data stream is divided into chunks. Each chunk is preceded by its size in bytes.

TBC

Method 2

Delimiters with length encoding

Although a normal delimiter between each string by itself works okay, it will fail in the case where any string contains the delimiter too

  • By encoding the length of each string prior to the delimiter, we avoid this
  • Time complexity : where is a number of strings in the input array.