Your question is Cluster Resource Utilization Function. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Workday Cloud Platform records task execution logs for a compute cluster. Each log identifies when a task ran and how many CPU units it consumed. Implement a function that calculates the cluster's peak CPU utilization percentage at any point in time.
Treat every task interval as half-open: a task contributes resources at times start <= t < end. If multiple tasks overlap, their CPU requirements are added. The cluster's utilization may exceed 100 if its capacity is oversubscribed. Return 0.0 when there are no valid task intervals.
Implement calculate_peak_utilization(tasks, cluster_capacity). tasks is a list of lists, where each task has the form [start, end, cpu_units]. start and end are integer timestamps, cpu_units is a nonnegative integer, and start < end. cluster_capacity is a positive integer representing total CPU units. Return a floating-point percentage rounded to two decimal places.
def calculate_peak_utilization(tasks, cluster_capacity):