There is a company which has a CEO and a hierarchy of employees. All employees have a unique ID, name, and a pointer to their manager and their reports.
Please implement the whoIsOurBoss() method to find the closest manager for two given employees (i.e. the manager farthest from the CEO that both employees report up to).
这道题本质上是公司组织树上的最近公共祖先(LCA)问题:给定两名员工,找到他们共同汇报路径中离 CEO 最远的那个共同经理,也就是“最近共同上级”。常见做法是先分别记录两个人到 CEO 的路径,再从根节点开始比较;也可以先把两人的深度对齐,然后同步向上移动,直到找到第一个相同节点。题目重点在于理解“manager farthest from the CEO that both employees report up to”这一表述,它对应的就是树结构中的 LCA。