Compute the average processing time for each machine from paired start and end logs.
You are given a list of process log records. Each record belongs to a machine and contains a process id, the machine id, a timestamp, and an event type indicating whether the process started or ended.
For every machine, consider all of its completed processes and compute the average processing time as:
Return the result for each machine, typically ordered by machine id.
A process duration is the difference between its end timestamp and start timestamp for the same process id on the same machine.
Input Format
- A list of log records.
- Each record contains:
- process id
- machine id
- timestamp
- event type (start or end)
- Every completed process has exactly one start and one end record.
Output Format
- Return the average processing time for each machine.
- Each result should identify the machine and its average duration.
Constraints
- Each process id is associated with one machine.
- Timestamps for a process are valid and allow duration calculation as end - start.
- Only completed processes contribute to the average.
- Use exact arithmetic or rounded output as required by the platform format.
Example 1
Input
logs = [[1,1,5,"start"],[1,1,10,"end"],[2,1,12,"start"],[2,1,18,"end"],[3,2,7,"start"],[3,2,9,"end"]]
Output
[[1,6],[2,2]]
Explanation
Machine 1 has durations 5 and 6, so its average is 11 / 2 = 5.5. If the platform requires integer output, it may be represented according to the specific format. Machine 2 has one duration of 2.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.