
Implement a function that, given a dasherId, a local pay-period interval [startLocalDateTime, endLocalDateTime), and a list of order events of the form {orderId, dasherId, type in {ACCEPT, FULFILL}, timestamp as LocalDateTime}, returns for each completed order in the interval the active duration between its ACCEPT and FULFILL and the total active duration across all completed orders. Assumptions: each completed order has exactly one ACCEPT before one FULFILL for the same dasher; events may be unsorted. Use LocalDateTime and Duration APIs. Explain the algorithm, its time and space complexity, and how you would adapt it to compute payment when pay rules are a function of active duration.