KLA / VO 面试真题解析:Company Hierarchy Data Structure 公司层级数据结构设计

54次阅读
没有评论

There are three companies: IBM, Intel, and Apple. A total of 8 people worked in these three companies.

Each person can be either a manager or a direct report to a manager.

Produce a class hierarchy diagram of a data structure to manage this information and their relationships.

The data structure should be able to support:

  • A static Company.Print() method to print the information, first iterating through the list of companies, printing out the company name, all their employees’names, social security ID, title, and the name of their direct reports or manager.
  • Then create a list of distinct individuals and print out their names.

这道题考察的是面向对象建模与层级关系设计。需要先抽象出 Company、Person 以及员工角色之间的关系,既要能表达“公司—员工—经理 / 下属”的树状或图状结构,也要避免同一个人在不同公司或多重关系下产生重复记录。实现时通常会为个人信息、职位信息、上下级关系分别建模,并通过集合或映射维护公司列表与去重后的人员列表。输出要求强调遍历公司时按层级打印员工信息,再输出所有不重复的个人姓名,因此重点是数据结构设计、关联维护和去重策略。

正文完
 0