Tap here to switch tabs
Problem
Submissions

Problem: Maximum Employees to Be Invited to a Meeting

Try to solve the Maximum Employees to Be Invited to a Meeting problem.

Statement

A company is planning a meeting and has nn employees, labeled from 00 to n−1n - 1. Each employee has a single favorite person whom they wish to sit next to at a round table. The employees are represented by an integer array favorite of length nn, where favorite[i] denotes the favorite employee of employee i.

An employee will attend the meeting if and only if they can sit directly adjacent to their favorite person at the round table. The round table can seat any number of employees.

Return the maximum number of employees that can be invited to the meeting.

Constraints:

  • n ==== favorite.length

  • 2≤2 \leq n ≤105\leq 10^5

  • 0≤0 \leq favorite[i] ≤\leq n −1- 1

  • favorite[i] ≠\neq i

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Employees to Be Invited to a Meeting

Try to solve the Maximum Employees to Be Invited to a Meeting problem.

Statement

A company is planning a meeting and has nn employees, labeled from 00 to n−1n - 1. Each employee has a single favorite person whom they wish to sit next to at a round table. The employees are represented by an integer array favorite of length nn, where favorite[i] denotes the favorite employee of employee i.

An employee will attend the meeting if and only if they can sit directly adjacent to their favorite person at the round table. The round table can seat any number of employees.

Return the maximum number of employees that can be invited to the meeting.

Constraints:

  • n ==== favorite.length

  • 2≤2 \leq n ≤105\leq 10^5

  • 0≤0 \leq favorite[i] ≤\leq n −1- 1

  • favorite[i] ≠\neq i