Back to problems

CPU Usage Analysis

Algorithm · Uber · Medium

You have a record of CPU events in a 2D string array logs. Each entry is a triple: task_name, an action that is either "enter" or "exit", and a timestamp. "enter" means the task began. "exit" means the task finished. Your job is to compute the total time the CPU spent actively working on every task. The CPU is single-threaded — it handles exactly one task at any moment. Tasks can be interleaved, and when the currently running task finishes, the CPU always picks up the most…

Checking your access…