Algorithm · Amplitude · Medium
You are given a set of employee records that define a reporting structure. Each employee may have a list of direct reports (children), or each employee may be assigned a single manager (managerId). The exact representation will be made clear in the input. Your task is to examine the full reporting graph and determine whether it contains any cycle. A cycle exists if there is a path where an employee is reachable from themselves by following the reporting edges — directly or…