Drill

ProblemsTypeScript › production

How busy was the line

mediumproductionTypeScript

A shift board shows what share of the planned time the line was actually running.

utilisationPercent(runMinutes: int, plannedMinutes: int) → int

Solve it in the editor →

Where you start

function utilisationPercent(runMinutes: number, plannedMinutes: number): number {
  
}

Worked examples

CallResult
utilisationPercent(420, 480)88
utilisationPercent(480, 480)100
utilisationPercent(500, 480)100
utilisationPercent(0, 480)0

Hint

Round first, then cap. Capping first hides the rounding.

Reference solution in TypeScript
function utilisationPercent(runMinutes: number, plannedMinutes: number): number {
  if (plannedMinutes <= 0 || runMinutes <= 0) return 0;
  const pct = Math.floor((runMinutes * 100 + Math.floor(plannedMinutes / 2)) / plannedMinutes);
  return Math.min(100, pct);
}

The same problem in another language

More production problems in TypeScript