Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Cluster Resource Utilization Function
00:00
5 left

Cluster Resource Utilization Function

MediumPython

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):
Interviewer

Your question is Cluster Resource Utilization Function. Start with the requirements in the Question tab.

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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.