Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Cluster Resource Utilization Function

MediumPython00:00
Practice interviewer
In session
5 left
00:00

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.

You need to log in / sign up to run or submit.

Problem

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.

Formal Specification

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.

Constraints

  • 0 <= len(tasks) <= 10^5
  • 0 <= start < end <= 10^9
  • 0 <= cpu_units <= 10^6
  • 1 <= cluster_capacity <= 10^9
  • Task intervals are half-open: start <= t < end

Function Signature

def calculate_peak_utilization(tasks, cluster_capacity):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output