Skip to content

Commit e6666bf

Browse files
committed
2127. Maximum Employees to Be Invited to a Meeting: RETRY
1 parent 55339ff commit e6666bf

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

src/solution/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,3 +1606,4 @@ mod s2122_recover_the_original_array;
16061606
mod s2124_check_if_all_as_appears_before_all_bs;
16071607
mod s2125_number_of_laser_beams_in_a_bank;
16081608
mod s2126_destroying_asteroids;
1609+
mod s2127_maximum_employees_to_be_invited_to_a_meeting;
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* [2127] Maximum Employees to Be Invited to a Meeting
3+
*
4+
* 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.
5+
* 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.
6+
* Given a 0-indexed integer array favorite, where favorite[i] denotes the favorite person of the i^th employee, return the maximum number of employees that can be invited to the meeting.
7+
*
8+
* Example 1:
9+
* <img alt="" src="https://assets.leetcode.com/uploads/2021/12/14/ex1.png" style="width: 236px; height: 195px;" />
10+
* Input: favorite = [2,2,1,2]
11+
* Output: 3
12+
* Explanation:
13+
* The above figure shows how the company can invite employees 0, 1, and 2, and seat them at the round table.
14+
* All employees cannot be invited because employee 2 cannot sit beside employees 0, 1, and 3, simultaneously.
15+
* Note that the company can also invite employees 1, 2, and 3, and give them their desired seats.
16+
* The maximum number of employees that can be invited to the meeting is 3.
17+
*
18+
* Example 2:
19+
*
20+
* Input: favorite = [1,2,0]
21+
* Output: 3
22+
* Explanation:
23+
* 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.
24+
* The seating arrangement will be the same as that in the figure given in example 1:
25+
* - Employee 0 will sit between employees 2 and 1.
26+
* - Employee 1 will sit between employees 0 and 2.
27+
* - Employee 2 will sit between employees 1 and 0.
28+
* The maximum number of employees that can be invited to the meeting is 3.
29+
*
30+
* Example 3:
31+
* <img alt="" src="https://assets.leetcode.com/uploads/2021/12/14/ex2.png" style="width: 219px; height: 220px;" />
32+
* Input: favorite = [3,0,1,4,1]
33+
* Output: 4
34+
* Explanation:
35+
* The above figure shows how the company will invite employees 0, 1, 3, and 4, and seat them at the round table.
36+
* Employee 2 cannot be invited because the two spots next to their favorite employee 1 are taken.
37+
* So the company leaves them out of the meeting.
38+
* The maximum number of employees that can be invited to the meeting is 4.
39+
*
40+
*
41+
* Constraints:
42+
*
43+
* n == favorite.length
44+
* 2 <= n <= 10^5
45+
* 0 <= favorite[i] <= n - 1
46+
* favorite[i] != i
47+
*
48+
*/
49+
pub struct Solution {}
50+
51+
// problem: https://leetcode.com/problems/maximum-employees-to-be-invited-to-a-meeting/
52+
// discuss: https://leetcode.com/problems/maximum-employees-to-be-invited-to-a-meeting/discuss/?currentPage=1&orderBy=most_votes&query=
53+
54+
// submission codes start here
55+
56+
impl Solution {
57+
pub fn maximum_invitations(favorite: Vec<i32>) -> i32 {
58+
0
59+
}
60+
}
61+
62+
// submission codes end
63+
64+
#[cfg(test)]
65+
mod tests {
66+
use super::*;
67+
68+
#[test]
69+
#[ignore]
70+
fn test_2127_example_1() {
71+
let favorite = [2, 2, 1, 2];
72+
73+
let result = 3;
74+
75+
assert_eq!(Solution::maximum_invitations(favorite), result);
76+
}
77+
78+
#[test]
79+
#[ignore]
80+
fn test_2127_example_2() {
81+
let favorite = [1, 2, 0];
82+
83+
let result = 3;
84+
85+
assert_eq!(Solution::maximum_invitations(favorite), result);
86+
}
87+
88+
#[test]
89+
#[ignore]
90+
fn test_2127_example_3() {
91+
let favorite = [3, 0, 1, 4, 1];
92+
93+
let result = 4;
94+
95+
assert_eq!(Solution::maximum_invitations(favorite), result);
96+
}
97+
}

0 commit comments

Comments
 (0)