Facebook | Phone | interesting string decode question. How to solve?
Anonymous User
1473

Zenconde is a type of encoding that supports 3 types of values:

  • ASCII string
  • integer
  • list

Zencode is defined as follow:

  • integer is encoded as "ie"
  • ASCII string is encoded as ":"
  • list of values: "le", where contents consists of Zencoded elements of the list, in order, concatenated. A list can contain a mix of integers, ASCII strings and sub-lists.

The goal of this exercise is to write a parser that can read a Zencode string. The inputs and outputs for this function are described below:

INPUT: String zencodedData -- the Zencoded string
OUTPUT: an Object that represents the underlying data encoded in "zencodedData"

10 -> "i10e"
"word" -> "4:word" ( 4 here is the length of the "word" )
[1, [0]] -> "li1eli0eee" ( "e" means end - 1 e for end of list, 1 e for end of int, and 1 e again for end of list ) :: "l" mean start of list/array

Input is the right side. Output is left.
Example:

Input: "li1eli0eee"
Output: [1, [0]]

Input: "lli456eee"
Output: [[456]]

I couldn't solve it in time. ANy thoughts? Using stack based approach?

Comments (7)