java.lang.Object
g2101_2200.s2127_maximum_employees_to_be_invited_to_a_meeting.Solution

public class Solution extends Object
2127 - Maximum Employees to Be Invited to a Meeting.<p>Hard</p> <p>A company is organizing a meeting and has a list of <code>n</code> employees, waiting to be invited. They have arranged for a large <strong>circular</strong> table, capable of seating <strong>any number</strong> of employees.</p> <p>The employees are numbered from <code>0</code> to <code>n - 1</code>. Each employee has a <strong>favorite</strong> person and they will attend the meeting <strong>only if</strong> they can sit next to their favorite person at the table. The favorite person of an employee is <strong>not</strong> themself.</p> <p>Given a <strong>0-indexed</strong> integer array <code>favorite</code>, where <code>favorite[i]</code> denotes the favorite person of the <code>i<sup>th</sup></code> employee, return <em>the <strong>maximum number of employees</strong> that can be invited to the meeting</em>.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2021/12/14/ex1.png" alt="" /></p> <p><strong>Input:</strong> favorite = [2,2,1,2]</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong></p> <p>The above figure shows how the company can invite employees 0, 1, and 2, and seat them at the round table.</p> <p>All employees cannot be invited because employee 2 cannot sit beside employees 0, 1, and 3, simultaneously.</p> <p>Note that the company can also invite employees 1, 2, and 3, and give them their desired seats.</p> <p>The maximum number of employees that can be invited to the meeting is 3.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> favorite = [1,2,0]</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong></p> <p>Each employee is the favorite person of at least one other employee, and the only way the company can invite them is if they invite every employee.</p> <p>The seating arrangement will be the same as that in the figure given in example 1:</p> <ul> <li> <p>Employee 0 will sit between employees 2 and 1.</p> </li> <li> <p>Employee 1 will sit between employees 0 and 2.</p> </li> <li> <p>Employee 2 will sit between employees 1 and 0.</p> </li> </ul> <p>The maximum number of employees that can be invited to the meeting is 3.</p> <p><strong>Example 3:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2021/12/14/ex2.png" alt="" /></p> <p><strong>Input:</strong> favorite = [3,0,1,4,1]</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong></p> <p>The above figure shows how the company will invite employees 0, 1, 3, and 4, and seat them at the round table.</p> <p>Employee 2 cannot be invited because the two spots next to their favorite employee 1 are taken.</p> <p>So the company leaves them out of the meeting. \</p> <p>The maximum number of employees that can be invited to the meeting is 4.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>n == favorite.length</code></li> <li><code>2 <= n <= 10<sup>5</sup></code></li> <li><code>0 <= favorite[i] <= n - 1</code></li> <li><code>favorite[i] != i</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maximumInvitations

      public int maximumInvitations(int[] fav)