Ask AI
Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.
Open Claude Desktoptrees · department-parity · levels
The organizer’s problem statement is available at the official source link.
department tree
Department parity constrains the head ID
Each connected tree is a department. Even-sized departments require the head to have the smallest ID; odd-sized departments require the largest. Team strength is the sum of employee levels.
| Department size | Head ID rule | Team strength |
|---|---|---|
| even | minimum ID | sum of employee levels |
| odd | maximum ID | sum of employee levels |
- 1
Find each department head
A department is a tree; its size parity determines whether its head has the minimum or maximum employee ID. - 2
Assign employee levels
The head is level 1; each employee is one level below their manager. - 3
Sum by department type
Add levels separately for employees in even-sized and odd-sized departments.
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|12 lines, 156 charsRun output
Run your code to see output.