Panda Guru LogoPanda
Guru

Fivetran | Data Engineer phone interview | Decode compressed string to frequency array

Round 1

Questions: The input string contains digits 0-9 and parentheses (). The digits outside the parentheses are mapped to lowercase English alphabets. The digits inside the parentheses are mapped to the frequencies of the corresponding alphabets in the order that they appear in the string.

Example 1
Input string: '1224#26#'
This input string is an encoding of 'abxz'.

Example 2
Input string: '1(2)2(3)324#26#(5)'
This input string is an encoding of 'aabbbcxzzzzz'.

The encoding is similar to the example above except the parentheses contain the frequency of each corresponding character when it's greater than 1. For example,

('->' stands for 'maps to')
In 'aa', a is seen 2 times, so a -> 1 and 2 times -> (2); therefore 'aa' becomes 1(2).
In 'zzzzz', z is seen 5 times, so z -> 26# and 5 times -> (5); therefore 'zzzzz' becomes 26#(5).

Return
Given a string, return a frequency array containing the counts of the alphabets in the string.

For example, the input string 'abxz' should return:

[1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1] -> You need to return this array.
[a.b................................................................x....z] -> I drew this for your convenience.

Follow-up Question

What would be the difficulty of this question? Easy, Medium, Hard..?

Candidate's Approach

My solution was able to crack the first example but not the second one because I forgot to account for the parentheses when I started to code. My bad. Later, I tried to fix my code but I didn't have enough time. When I was walking the interviewer through my thought process, I explained that I need to account for it but forgot about it later for some reason. I guess it was interview pressure.

Interviewer's Feedback

The interviewer did not stop me from making the mistake before I got too deep into the trenches. A lesson learned the hard way! After going through many discussions forums, interview preparation guides, and coaching websites, I was under the assumption that interviewers usually stop the candidate from making an obvious mistake by providing subtle hints but it's not true all the time. My bad again for making such an assumption.