Skip to content

Practice Maximum Employees to Be Invited to a Meeting

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#2127
LeetCode Problem

Maximum Employees to Be Invited to a Meeting

Problem Statement

A company is organizing a meeting and has a list of n employees, waiting to be invited. They have arranged for a large circular table, capable of seating any number of employees. The employees are numbered from 0 to n - 1. Each employee has a favorite person and they will attend the meeting only if they can sit next to their favorite person at the table. The favorite person of an employee is not themself. Given a 0-indexed integer array favorite, where favorite[i] denotes the favorite person of the ith employee, return the maximum number of employees that can be invited to the meeting.

Source: Maximum Employees to Be Invited to a Meeting on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
favorite = [2,2,1,2]
Output
3

# Example 2

Input
favorite = [1,2,0]
Output
3

# Example 3

Input
favorite = [3,0,1,4,1]
Output
4

Constraints

n == favorite.length
2 <= n <= 10^5
0 <= favorite[i] <= n - 1
favorite[i] != i

Related LeetCode Problems

Practice more problems similar to Maximum Employees to Be Invited to a Meeting.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.