Design an Employee Directory Structure
Anonymous User
2138

Recently a friend of mine was asked this question during his interview with one the top e-commerce companies.

It goes something like this :

Write a program for to create a directory of an organization where an employee will have attributes id, name, position and manager. Two main features need to be implemented i.e.

  1. Searching on the basis of name.

  2. Prefix search for the name should also be supported.

  3. For any employee list all the subordinates. Example for the CEO all the employees should get listed.

My Approach : Store the employee records in an N-ary Tree. The current manager becomes the parent. For a quick name look up and insertion, use a hash table something like unordered_map<string (name), vector >.
Additionally a sepreate trie for prefix based listing. Any thoughts on a better approach?

Comments (1)