FastPrepFinish Time of Fixed-Length CPU Tasks

Finish Time of Fixed-Length CPU Tasks

Google logoGoogle● MediumFULLTIMEONSITE INTERVIEW

Problem statement

A machine has maxCpus identical CPUs. You are given an integer array startTimes, where startTimes[i] is the scheduled start time of task i. Every task takes exactly executionTime time units on one CPU. The array is not necessarily sorted and may contain equal values.

Run all tasks under these rules:

The problem statement continues
Pro

Examples

Example 1

startTimes = [1,4,6]executionTime = 5maxCpus = 2return = 11
  • Task at 1 runs on CPU A from 1 to 6.
  • Task at 4 runs on CPU B from 4 to 9.
  • At time 6, CPU A becomes free just as the third task is scheduled, so it runs from 6 to 11.

The last task finishes at 11.

FastPrep Pro
Reported in 1 Google interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week
See Google hiring insights
CodePython 3
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Google interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week