Entitlement SLA Breaches
MediumIntervals · SalesForce
A support platform measures each case against an entitlement SLA. You are given:
cases: rows[case_id, opened_at, resolved_at, limit]. The case's clock runs fromopened_attoresolved_at.pauses: rows[case_id, start, end]. While a pause is active, that case's SLA clock is stopped. A pause covers the half-open interval[start, end).
A case's adjusted time is resolved_at - opened_at minus the amount of time inside [opened_at, resolved_at) that is covered by at least one of its pauses. In particular:
- Pauses of the same case may overlap or repeat; overlapping time is subtracted only once.
- A pause may start before
opened_ator end afterresolved_at; only the part inside the case's window counts. - Pauses whose
case_iddoes not match any case are ignored.
A case breaches its SLA when its adjusted time is strictly greater than limit. Return the ids of all breaching cases sorted in ascending lexicographic order (empty list if none).
Example 1
- Input:
- cases = [["C1", 100, 160, 25], ["C2", 0, 50, 30], ["C3", 0, 20, 20]], pauses = [["C1", 110, 130], ["C1", 120, 140], ["C2", 40, 90]]
- Output:
- ["C1", "C2"]
- Explanation
- C1 is open for 60 units. Its pauses overlap, so together they cover 110-140, which is 30 units (not 20 + 20 = 40); 60 - 30 = 30 > 25, a breach. C2 is open for 50 units, but only 40-50 of its pause lies inside that window, so 50 - 10 = 40 > 30. C3 uses exactly its limit of 20, which is not a breach.
Example 2
- Input:
- cases = [["A", 0, 100, 50]], pauses = [["A", 10, 30], ["A", 30, 60], ["B", 0, 100]]
- Output:
- []
- Explanation
- A's pauses touch at 30 and together cover 50 units, so A's adjusted time is 50, equal to its limit. The pause for
Bbelongs to a case that does not exist and is ignored.
Example 3
- Input:
- cases = [["X", 50, 80, 10], ["Y", 5, 5, 0]], pauses = [["X", 0, 40], ["X", 90, 120]]
- Output:
- ["X"]
- Explanation
- Both of X's pauses lie completely outside its open window 50-80, so nothing is subtracted and 30 > 10. Y was opened and resolved at the same moment, so its time is 0.
Constraints
0 <= cases.length, pauses.length <= 10^5- Case ids are unique non-empty strings
0 <= opened_at <= resolved_at <= 10^9start < end, andstart,endare integers (they may lie outside the case's window)0 <= limit <= 10^9