Status: 3+ years of exp at no name compamny
Position: Software Engineer
Location: San Francisco, CA
Date: May 2020
Technical Phone Screen
you are given a string
"1:max:4, 2:ann:0, 3:alb:2, 4:edmond:2"
the format of the string is "id:name:manager_id"
Print this:
Ann
- Alb
- edomnd
-- maxExplanation : Alb and edmond's manager is Ann so they are under Ann. Max's manager is edmond so he is under edmond.
After thinking sometime I thought this was graph problem and started creating a graph. Midway to the code I asked Interviewer what if there would be another person in the srting who doesn't have any manager or they doesn't have any one working under them.
They said it would print separately above or before Ann.
So, for string "1:max:4, 2:ann:0, 3:alb:2, 4:edmond:2, 5: bruce:0" it would print
Bruce
Ann
- Alb
- edomnd
-- max
or
Ann
- Alb
- edomnd
-- max
BruceI solved the question by doing topological sort doing Kahn's Algorithm(BFS) and explained my approch.
it took me a while to understand the question and code it completely. There were some small errors which pointed out by the interviewer.
By the end of 1 hour My code was working perfectly fine and provided the output as expected.
I explained my approch and said this is BFS and explained the time complexity.
My Interviewer told me you have imolemented a DFS and not BFS. I was like I am pretty sure Kahn's Algorigthm is BFS and not DFS. Since, I didn't want to hurt interviewer's ego so I said okay you are right.
Also, my interviewer said my code was little messy and I thought my code was exact copy of Kahn's Algo in Python. There isn't any prettier way to do this.
Anyhoo I am not sure where did I mess up maybe interviewer was expecting to this probelm to be done via sorting.