Twilio | Phone (Coding) | Find List of Phone numbers
Anonymous User
1163

Find list of phone numbers of Managers who have reportees from multiple cities.
A manager can have himself as employee which should not be considered for this case.

Sample data set :
{{"emp1","emp2-mgr","Citi1","Phone1"},{"emp2","emp3-mgr","Citi2","Phone2"}}
// First employee ID, second - ManagerId , Citi, Phone number

Java Solution : Used 1 Hashmap to store Manager Id and Phonenumbers.
Creatd another Hashmap to save Manager ID , city name. Whenever I find a same manager ID in map for a different employeeID and city, I will append this to output list of phone numbers. and returned -- Took 25 minutes.

Extension to the problem :
Now find manager phone numbers considering the sublevels as well, Means if Emp1 is manager to Emp2 and Emp3 , where Emp2 has 2 more employees under him. Then we shoud find Emp1 if he or his sub ordinates have employees from different cities. Chain can have more depth as well.

Solution : I tried to implement with a stack , adding the ManagerIds to a new HashMap which holds another HashMap. I took a longer approach and could not finish in time ( Have 25 minutes for this problem). I told the interviewer that Tree traversla with DFS would be a good approarch , but by then it was too late. At the end interviewer also told that he was expecting me to write with DFS only for this.

Comments (3)