The Maximum Employees to Be Invited to a Meeting coding problem is a complex graph-based challenge. You are given a list of employees, where each employee has exactly one person they 'favorite'. You want to invite the maximum number of people to a round table such that every invited person sits next to their favorite person. This involves analyzing functional graphs where each node has exactly one outgoing edge.
This Hard-level question is frequently asked by top-tier companies like Google and Microsoft because it requires a deep understanding of graph structures, specifically cycles and chains. It tests a candidate's ability to handle two distinct cases: large cycles where everyone sits in a ring, and small cycles of size 2 where chains of people can be added to both sides of the pair. It's a masterclass in Topological Sort and Depth-First Search (DFS).
The problem uses Graph interview patterns, specifically cycle detection and Topological Sort. The graph is a collection of components, each containing exactly one cycle.
Imagine 4 people:
The biggest mistake is failing to distinguish between the two cases (large cycles vs. 2-cycles with chains). Candidates often try to find the longest path in the entire graph, but a round table requires specific adjacency. Another common error is not summing up the results of all 2-cycle components, while only taking the maximum of the larger cycles.
Practice identifying 'Functional Graphs' (where each node has out-degree 1). They always consist of components with exactly one cycle. Understanding how to use Kahn's algorithm (Topological Sort) to 'peel away' the nodes that aren't part of a cycle is a vital skill for these types of problems.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Longest Cycle in a Graph | Hard | Solve | |
| Sort Items by Groups Respecting Dependencies | Hard | Solve | |
| All Ancestors of a Node in a Directed Acyclic Graph | Medium | Solve | |
| Course Schedule IV | Medium | Solve | |
| Find Eventual Safe States | Medium | Solve |