Amplitude interview question
Detect a cycle in an employee-to-manager reporting list
- Company:
- Amplitude
- Type:
- Coding
- Difficulty:
- Medium
- Reported:
- June 2, 2026
Problem
You are given a list of employees as (employee_id, manager_id) pairs. manager_id is None for an employee with no manager. Each employee has at most one manager. A manager id that does not appear as an employee is treated as an external person and ends the chain.
Add a validation rule: return True if the reporting chain contains a cycle (some employee is, directly or indirectly, their own manager), otherwise False.
Example 1
Input: [(1, None), (2, 1), (3, 2), (4, 2)]
Output: False
Every chain ends at employee 1, who has no manager.
Example 2
Input: [(1, 3), (2, 1), (3, 2), (4, None)]
Output: True
1 reports to 3, 3 reports to 2, and 2 reports to 1.
Constraints
0 <= number of employees <= 10^5- Employee ids are unique.
- An employee listing themselves as manager is a cycle.
Reported by candidates or drawn from publicly available sources, and rewritten in our own words. Pathwise Prep does not publish confidential assessment content. Report a concern