Amazon | Phone | CSV Parser

Position: SDE2
Location: Toronto

First I got some behavioral questions and then I got the following programming question.

Given a string, convert it to a list of values separeted by coma. Called CSV parser.

Example 1

Input = ' "a","b","c" '

Output = [a, b, c]
// We are not adding the double quotes in the strings

Example 2

Input = "a","b,","c"

Output = [a, "b," ,c]
// If there is a comma in between the double quotes then it is part of the string and we add it into the result, so b will have the comma.

Example 3

Input = ' a,"b,",c '

Output = [a,"b,",c]
// We can also get the string without the double quotes around each value and use the comma to separate the values that doesn't have double
quotes and add the inner commas in the values that have double quotes, for example the b have a comma in between the double quotes, but the a and c doesn't have double quotes around so we use the comma to separate them.

We can assume that:

  • the string will fit in the memory.
  • if we have double quotes, we will get the same number of open double quotes as close double quotes

Hope this makes sense since I didn't find a problem that cover this task.
I was rejected but I will keep studying and hopefully in the future I will perform better.

Comments (7)