Maximum Employees to Be Invited to a Meeting
Real-world version: Seating Staff Beside the One They NamedThe statement here is our own: the same inputs, outputs and technique.
Each of n staff, numbered 0 through n - 1, names exactly one other member of staff in pick, and nobody names themselves.
The staff are to be seated round one round table. A member of staff will only sit down if the person they named ends up seated directly beside them, on either side.
Return the largest number of staff that can be seated.
Examples
Example 1
- Input
- pick = [1, 0, 1, 2]
- Output
- 4
Staff 0 and 1 name each other, so they sit side by side. Staff 2 named 1 and staff 3 named 2, so those two line up outwards from the pair and all four are seated.
Example 2
- Input
- pick = [1, 2, 3, 4, 0]
- Output
- 5
The five name each other round in a ring, so seating them in that order puts everyone beside the person they named.
Example 3
- Input
- pick = [1, 0, 3, 2]
- Output
- 4
Two separate pairs name each other. Each pair sits together and the two pairs take different stretches of the table, so all four are seated.
Constraints
- 2 <= pick.length <= 10^5
- 0 <= pick[i] <= pick.length - 1
- pick[i] != i
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def maximum_invitations(pick: list[int]) -> int:public int maximumInvitations(int[] pick)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Find Eventual Safe StatesReal-world version: States From Which the Batch Always HaltsMedium
- Longest Increasing Path in a MatrixReal-world version: Tallest Stack AscentHard
- Longest Cycle in a GraphReal-world version: Longest Loop in a Relay NetworkHard
- Loud and RichReal-world version: Steadiest Hand in the WorkshopMedium