Drill

ProblemsC# › events

How many minutes between two clock times

easyeventsMathC#

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

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

C# needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.

Solve it in Python →

Where you start

public int HoursBetween(int startMinutes, int endMinutes) {
    
}

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 C#
public int HoursBetween(int startMinutes, int endMinutes) {
    int diff = endMinutes - startMinutes;
    return ((diff % 1440) + 1440) % 1440;
}

The same problem in another language

More events problems in C#