Practice Average Time of Process per Machine
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Tables: Activity(machine_id INT, process_id INT, activity_type ENUM, timestamp FLOAT). Activity has key (machine_id, process_id, activity_type). activity_type is start or end and timestamp is in seconds. Each machine-process pair has both events, with start no later than end. For each machine, average the end-minus-start duration of its processes. Return machine_id and processing_time rounded to three decimals, in any order. Pair events by both machine_id and process_id.
Source: Average Time of Process per Machine on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Activity table: +------------+------------+---------------+-----------+ | machine_id | process_id | activity_type | timestamp | +------------+------------+---------------+-----------+ | 0 | 0 | start | 0.712 | | 0 | 0 | end | 1.520 | | 0 | 1 | start | 3.140 | | 0 | 1 | end | 4.120 | | 1 | 0 | start | 0.550 | | 1 | 0 | end | 1.550 | | 1 | 1 | start | 0.430 | | 1 | 1 | end | 1.420 | | 2 | 0 | start | 4.100 | | 2 | 0 | end | 4.512 | | 2 | 1 | start | 2.500 | | 2 | 1 | end | 5.000 | +------------+------------+---------------+-----------+
+------------+-----------------+ | machine_id | processing_time | +------------+-----------------+ | 0 | 0.894 | | 1 | 0.995 | | 2 | 1.456 | +------------+-----------------+
Related LeetCode Problems
Practice more problems similar to Average Time of Process per Machine.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.