Drill

ProblemsTypeScript › events

How many minutes between two clock times

easyeventsTypeScript

Two timestamps on the same day: return the signed forward distance in minutes, wrapping past midnight.

hoursBetween(startMinutes: int, endMinutes: int) → int

Solve it in the editor →

Where you start

function hoursBetween(startMinutes: number, endMinutes: number): number {
  
}

Worked examples

CallResult
hoursBetween(0, 60)60
hoursBetween(60, 0)1380
hoursBetween(1400, 100)140
hoursBetween(0, 1440)0

Hint

Subtract, then add 1440 if the result is not positive, and take modulo 1440.

Reference solution in TypeScript
function hoursBetween(startMinutes: number, endMinutes: number): number {
  const diff = endMinutes - startMinutes;
  return ((diff % 1440) + 1440) % 1440;
}

The same problem in another language

More events problems in TypeScript