Group Training Overdue Rollup
Learn this problemProblem statement
Every employee has one required training due day and either a completion day or -1 when the training has not been completed. Groups form a directed acyclic hierarchy: a group contains its direct employees and every employee contained by any direct or indirect subgroup.
For every group in groupNames, return two values:
- the number of distinct employees in that group's complete membership; and
- the sum of their overdue days on
checkDay.
An employee contributes overdue days only when the employee has not completed by checkDay. In that case, the contribution is max(0, checkDay - dueDay). The due day itself contributes 0. A completion day after checkDay is a future event and does not prevent an overdue contribution.
An employee reachable through multiple subgroup paths is counted once per group. Return rows in the same order as groupNames, with each row formatted as [distinctEmployeeCount, totalOverdueDays].
Function
groupOverdueRollup(employeeIds: String[], dueDays: int[], completionDays: int[], groupNames: String[], directEmployees: String[][], directSubgroups: String[][], checkDay: int) → int[][]Examples
Example 1
employeeIds = ["amy","ben","cy"]dueDays = [5,7,4]completionDays = [-1,8,6]groupNames = ["eng","platform","security"]directEmployees = [["amy"],["ben"],["cy"]]directSubgroups = [["platform","security"],[],[]]checkDay = 10return = [[3,5],[1,0],[1,0]]eng contains all three employees. Only amy is incomplete on day 10, contributing 10 - 5 = 5 overdue days. The other employees completed by the check day.
Example 2
employeeIds = ["a","b"]dueDays = [2,3]completionDays = [-1,-1]groupNames = ["root","left","right","shared"]directEmployees = [[],[],[],["a","b"]]directSubgroups = [["left","right"],["shared"],["shared"],[]]checkDay = 5return = [[2,5],[2,5],[2,5],[2,5]]The shared subgroup is reachable from root through two paths, but its two employees are counted once. Their overdue contributions are 3 and 2.
Constraints
1 <= employeeIds.length == dueDays.length == completionDays.length <= 2000.- Employee IDs are unique non-empty strings.
0 <= dueDays[i], checkDay <= 10^6.completionDays[i] == -1or0 <= completionDays[i] <= 10^6.1 <= groupNames.length == directEmployees.length == directSubgroups.length <= 1000.- Group names are unique non-empty strings.
- Every direct employee and subgroup name is known. Names are unique inside each direct-membership row.
- The subgroup relation is a directed acyclic graph.
- Every returned overdue-day total fits in a signed 32-bit integer.